【发布时间】:2015-05-17 15:30:58
【问题描述】:
当我编译我的项目时,它在 url http://localhost:12421/index.html 中运行
我可以在我的私人 IP 中运行它吗?假设http://192.168.1.212:12421/index.html 我试图浏览它,它给了我错误 错误请求 - 主机名无效
HTTP 错误 400。请求主机名无效。
【问题讨论】:
标签: asp.net
当我编译我的项目时,它在 url http://localhost:12421/index.html 中运行
我可以在我的私人 IP 中运行它吗?假设http://192.168.1.212:12421/index.html 我试图浏览它,它给了我错误 错误请求 - 主机名无效
HTTP 错误 400。请求主机名无效。
【问题讨论】:
标签: asp.net
例如,我有一个名为 myWebSite 的 ASP.NET 项目。
以下方法可以将http://localhost:12421/ 服务器地址 更改为 IP 地址,例如:192.168.1.7:80 一直对我有用。
c:\Windows\system32>,然后键入:netsh http add urlacl url=http://192.168.1.7:80/ user=everyone
然后按Enter 键。 URL reservation successfully added 消息。C:/Users/UserName/Documents/IISExpress/config/ 并打开applicationhost.config。applicationhost.config 文件的<sites> 部分中找到您的站点。<sites>
<site name="myWebSit" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="D:\myWebSit\myWebSit" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:12421:localhost" />
</bindings>
</site>
</sites>
现在将地址更改为您的 IP,而不是 localhost。例如:
<binding protocol="http" bindingInformation="*:80:192.168.1.7" />
properties。
在属性中选择 Web 选项卡,然后将 Project Url 文本框内容更改为您的地址。例如:http://192.168.1.7:80/ 并单击 Create Virtual Directory 按钮。 The virtual directory was created successfully. 消息。现在,您应该可以通过自己的 IP 地址在 Visual Studio 中运行您的项目了。
【讨论】:
您尝试从哪里访问?您尝试访问的机器必须在同一网络中,如果检查您没有阻止防火墙上的连接(可能是 Windows 的防火墙)。 您使用的是 IIS 还是 IIS Express?如果您使用的是 IIS Express,则需要手动编辑 applicationhost.config 文件并更改 bindingInformation '::'。
【讨论】:
通常,当您从 Visual Studio 运行 asp.net 应用程序时,它会从安装的 asp.net 开发服务器运行。因此,它将在 localhost:port 中运行。但是如果你想使用 ip 地址运行,那么你必须使用 iisexpress 并在 vs project->properties->web 中提供带有 ip 地址的端口号。按照地址中给出的步骤进行操作:https://forums.adobe.com/thread/1486251
您是否尝试在 IIS 上部署后浏览您的应用程序? 要在 IIS 上使用 ip 地址浏览,请按以下方式查看:
谢谢
【讨论】: