连接到Visual Studio通过局域网debuggingIIS Express服务器
我有一个在VS2012开发的testingASP.NET MVC3应用程序。 当我开始debugging时,通过请求http://localhost:<portnumber>从主机访问应用程序。 但是,如果我尝试通过http://<ip>:<portnumber>从Intranet中的远程计算机访问相同的应用程序,则会出现HTTP error 400: Bad request. Invalid Host Name. HTTP error 400: Bad request. Invalid Host Name. 只要在IIS Express上运行,任何服务器configuration都无法访问。
有没有解决这个问题的方法?
更新
我做了一个video,更好地描述了这个过程, https://youtu.be/5ZqDuvTqQVs
如果您使用的是VS2013或更高版本,请确保以pipe理员身份运行它以使其正常工作。
打开%USERPROFILE%\My Documents\IISExpress\config\applicationhost.config (在VS2015中它可能是$(solutionDir)\.vs\config\applicationhost.config .vs $(solutionDir)\.vs\config\applicationhost.config )文件。 在里面你应该看到这样的东西:
<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将不同)。
注意:如果不起作用,试着用bindingInformation="*:8080:可以删除asterix。
然后确保您的防火墙允许在该端口上传入连接。 您可能需要重新启动系统或至lessVisual Studio才能让IISExpress重新加载configuration文件。
如果这不起作用,请看这个答案: https : //stackoverflow.com/a/5186680/985284
除了修改iisexpressconfiguration文件外,有时候还需要像下面那样运行命令。
netsh http add urlacl url = http:// *:49419 / user = Everyone
由于我无法对@Garret Fogerlie的post添加评论,并回复评论者的问题(@ Y.Ecarri和@SamuelEdwinWard),我遵循了Garret的build议,使用Visual Studio 2013,在Admin模式下运行它并更改application.config文件。
启动debugging后,看到我得到了同样的错误信息,我回到了application.config ,看到我的网站的新条目已经被创build就像Y.Ecarri的问题。
所以我停止debugging, 保持我的解决scheme在Visual Studio中打开 ,并再次编辑application.config文件的新条目。 我也完全删除*唱歌和localhost ,所以我有以下新条目:
<binding protocol="https" bindingInformation=":44300:" />
VisualStudio 2015非pipe理员
-
在您的解决scheme目录中,在
.vs\config\applicationHost.config文件中更改该行<binding protocol="http" bindingInformation="*:44302:localhost" />至
<binding protocol="http" bindingInformation=":44302:" />(44302是你的港口)
-
从pipe理员命令提示符下:
一世。 启用非pipe理员绑定到端口
netsh http add urlacl url=http://*:44302/ user=EveryoneII。 允许通过防火墙
netsh advfirewall firewall add rule name="IISExpress visualstudio app" protocol=tcp localport=44302 dir=in action=allow
- 从VisualStudio开始debugging
如何避免以pipe理员身份运行Visual Studio
使用Garret's和@ shangkeyun的答案,您可以实现连接到正在运行的网站,而无需以pipe理员用户身份运行Visual Studio:
- 打开
%USERPROFILE%\My Documents\IISExpress\config\applicationhost.config - 使用
name=MySiteNamesearch您的网站 - 复制
<bindings>部分中现有的<binding>项目。 你现在应该有两行binding。 - 去除bindingInformation中的“localhost”部分。
-
现在应该看起来像这样,假设端口是
12345:<binding protocol="http" bindingInformation="*:12345:localhost" /> <binding protocol="http" bindingInformation="*:12345:" /> -
以pipe理员身份运行以下cmd,删除所有防火墙限制:
netsh http add urlacl url=http://*:49419/ user=Everyone
感谢byteit:
在Documents / IISExpress / config中转到applicationhost.config
find您正在处理的特定网站的条目:
加:
<binding protocol="http" bindingInformation="*:<your site port>:*" />
在现有的前面
<binding protocol="http" bindingInformation="*:<your site port>:localhost" />
为了在没有VS2013的情况下实现解决scheme,请在重新启动时为您创build一个新的网站xml条目。 您将需要以pipe理员身份运行。
这对我来说是有效的:
- 启动IISpipe理器
- 添加一个新的虚拟目录,指向项目文件夹(在我的情况下是
C:\VSProjects) - 在IISpipe理器中select新的虚拟目录。 从选项列表中select
Directory Browsing。 在右侧有一个Enablebutton。 点击它。
现在我可以通过mypcname\VSProjects\myProj\outputBinViewer访问我的文件夹和项目bin。
经过上面的configuration,我不得不在pipe理模式下运行Visual Studio。
你们中的一些人可能会花费很多时间使用%USERPROFILE%目录进行修改和testing。 如果您正在VSdebugging上运行,请使用$(solutionDir).vs \ config \ applicationhost.config
- 为什么ASP.NET Identity接口为主键和外键使用string?
- 源代码pipe理中的.vs \ config \ applicationhost.config
- 如何使用msbuild发布Web?
- web.config编译/集合元素是做什么的?
- Server.MapPath(“。”),Server.MapPath(“〜”),Server.MapPath(@“\”),Server.MapPath(“/”)。 有什么不同?
- 我应该什么时候使用OWIN Katana?
- ASP.NET中的多选下拉列表
- 在垃圾桶和GAC中,哪一个被使用?
- 用jQuery调用ASP.NET PageMethod / WebMethod – 返回整个页面