我有一个测试ASP.NET MVC3应用程序开发于VS2012.当我开始调试应用程序时,会通过请求http://localhost:<portnumber>
从主机访问该应用程序.但是,如果我试图通过http://<ip>:<portnumber>
从内部网中的远程计算机访问同一应用程序,我得到HTTP error 400: Bad request. Invalid Host Name.
,因为它在IIS Express上运行,任何服务器配置都是不可访问的.
有没有办法解决这个问题?
我有一个测试ASP.NET MVC3应用程序开发于VS2012.当我开始调试应用程序时,会通过请求http://localhost:<portnumber>
从主机访问该应用程序.但是,如果我试图通过http://<ip>:<portnumber>
从内部网中的远程计算机访问同一应用程序,我得到HTTP error 400: Bad request. Invalid Host Name.
,因为它在IIS Express上运行,任何服务器配置都是不可访问的.
有没有办法解决这个问题?
Update
我制作了一个更好地描述这个过程的视频,https://youtu.be/5ZqDuvTqQVs
如果您使用的是Visual Studio 2013或更高版本,请确保以管理员身份运行它,以使其正常工作.
%USERPROFILE%\My Documents\IISExpress\config\applicationhost.config
(in VS2015 it may be $(solutionDir)\.vs\config\applicationhost.config
) file. Inside you should see something like this:
<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>
将bindingInformation=":8080:localhost"
更改为bindingInformation="*:8080:*"
(在我的情况下,端口号8080将有所不同.)
Note:如果不起作用,请try 使用bindingInformation="*:8080:
,可以删除Asterix.
然后确保防火墙允许该端口上的传入连接.您可能需要重新启动系统,或者至少需要Visual Studio才能让IISExpress重新加载配置文件.
如果这不起作用,看看这个答案:https://stackoverflow.com/a/5186680/985284