我有一个ASP.NET Web应用程序项目Visual Studio 2013,我只将其用于测试目的。我使用的几乎是默认的项目设置:
- 运行该项目将启动IIS Express web服务
- web应用程序只接受来自
localhost
的请求——其他主机会产生Bad Request - Invalid Hostname
响应
我希望能够从局域网上的另一台机器发送请求和接收响应。我发现这可以通过修改%USERPROFILE%DocumentsIISExpressconfigapplicationhost.config
文件来启用,将//configuration/system.applicationHost/sites/site/bindings/binding[@bindingInformation]
属性的值从*:1728:localhost
更改为*:1728:*
。
这是可行的,但还有另一个恼人的问题:每当我在Visual Studio中重新打开项目时,就会在applicationHost.config
文件中创建一个重复的site
元素,bindingInformation
属性的旧值为*:1728:localhost
,这意味着我必须重复上述过程。是否有一种方法可以让IIS Express/View Studio使用现有的、修改过的site
配置元素,而不是创建新的配置元素?否则,是否有方法将bindingInformation
属性的默认值更改为*:1728:localhost
而不是*:1728:localhost
?
不要从:1728:localhost中删除localhost。仅重复:1728:localhost;:1728:192.168.1.1
不要更改已创建绑定中的bindingInformation
。只需添加一个新的binding
元素。像这样:
<site name="SitenameHere" id="11">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:Users**usernameHere**PathToProjectHere" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:1728:localhost" />
<binding protocol="http" bindingInformation="*:1728:*" />
</bindings>
</site>