使用IIS Express代替ASP.NET Development Server

来源:互联网 发布:淘宝全景图体验app 编辑:程序博客网 时间:2024/06/06 14:14

VS在本地调试网站的时候,默认情况下使用ASP.NET Development Server作为Web服务器,但是这个VS内置的Web服务外部不能访问,只能在本地通过localhost访问,如果我需要调试手机网页,在手机上就无法访问了,如果使用完整的IIS,又感觉太大了,而且每次都要重新部署,使用起来不方便。所以使用IIS Express用来调试网站最合适,首先功能上几乎和IIS一样,只是没有可视化的界面,其次和VS2010,VS2012集成在一起,使用方便。

下面总结一下在Windows 7,VS2010下配置IIS Express的过程:

1,升级VS2010到SP1,可以在这里下载到:

http://download.microsoft.com/download/E/B/A/EBA0A152-F426-47E6-9E3F-EFB686E3CA20/VS2010SP1dvd1.iso

2,安装IIS Express,可以在这里下载到:

http://search.microsoft.com/zh-cn/DownloadResults.aspx?q=IIS+Express

3,安装完成之后,在项目上点击右键就可以看到多出了一个IIS Express的菜单,如下:


点击”使用IIS Express...“,就可以配置使用IIS Express来启动网站了:


4,在项目>属性>Web中设置启动项目的URL:


5,默认情况下URL是:http://localhost:5001/,如果要支持外部访问,需要打开IIS Express的配置文件,增加主机头(Host Header)

IIS Express配置文件的位置位于:我的文档>IIS Express>config下,打开applicationhost.config文件,找到sites段:

        <sites>
            <site name="WebSite1" id="1" serverAutoStart="true">
                <application path="/">
                    <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation=":8080:localhost" />
                </bindings>
            </site>
            <site name="xunqiang" id="2">
                <application path="/" applicationPool="Clr2IntegratedAppPool">
                    <virtualDirectory path="/" physicalPath="E:\svn\develop\xunqiang" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation="*:5001:localhost" />
                    <binding protocol="http" bindingInformation="*:5001:192.168.0.103" />
                </bindings>
            </site>
            <siteDefaults>
                <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
                <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
            </siteDefaults>
            <applicationDefaults applicationPool="Clr4IntegratedAppPool" />
            <virtualDirectoryDefaults allowSubDirConfig="true" />
        </sites>

在bindings段下增加一行,其中bindingInformation的格式是:IP:PORT:Host Header。如上面增加的:

<binding protocol="http" bindingInformation="*:5001:192.168.0.103" />

表示可以通过http://192.168.0.103:5001/来访问网站了。

6,增加urlacl,以管理员运行cmd终端,通过netsh命令增加http://192.168.0.103:5001/地址

netsh http add urlacl url=http://192.168.0.103:5001/ user=everyone

7,把5001端口添加到防火墙的允许端口中:

打开防火墙:


点击”高级设置“:


点击”入站规则“:


新建一个规则,将TCP的5001端口设置到允许的端口中。

整个设置就完成了,就可以在其他机器上或者手机上通过IP地址来打开本地调试的网站了。


VS2010中可以可以设置IIS Express作为以后新建网站的默认Web服务器:


0 0
原创粉丝点击