在asp.net中更改服务器地址

RSt*_*yle 5 asp.net

当我编译我的项目时,它在 url http://localhost:12421/index.html 中运行

我可以在我的私有 ip 中运行它吗?让我们说http://192.168.1.212:12421/index.html 我试图浏览它,它给了我错误错误请求 - 无效的主机名

HTTP 错误 400。请求主机名无效。

Beh*_*zad 3

例如,我有一个ASP.NET名为myWebSite的项目。
以下将http://localhost:12421/ 服务器地址更改为IP地址的方法例如: 192.168.1.7:80总是对我有用。

  1. 在您的计算机上启用 IISExpress

Windows功能

  1. 添加 NetShare 预留在 Windows 中以管理员 身份打开命令行 ( CMD ) ,转至,然后键入: ,然后按键。 您应该会看到一条消息。c:\Windows\system32>
    netsh http add urlacl url=http://192.168.1.7:80/ user=everyoneEnter
    URL reservation successfully added

指令管理系统

  1. 转到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>
Run Code Online (Sandbox Code Playgroud)

现在将地址更改为您的 IP localhost。例如:

<binding protocol="http" bindingInformation="*:80:192.168.1.7" />
Run Code Online (Sandbox Code Playgroud)
  1. 将 Project Url 更改为自己的地址
    在 Visual Studio 上打开您的项目;右键单击您的启动项目并选择properties。在属性中选择选项Web卡,然后将项目 URL文本框内容更改为您的地址。例如:http://192.168.1.7:80/然后单击Create Virtual Directory按钮。
    您应该会看到一条The virtual directory was created successfully.消息。

VSWebTab

现在,您应该能够通过自己的 IP 地址在 Visual Studio 中运行您的项目。

参考