传统上,我在本地主机开发服务器上使用自定义域。大致如下:
dev.example.com
dev.api.example.com
这为我在使用外部api(如Facebook)时提供了很大的灵活性。这在过去与内置的Visual Studio Development Server一起工作得很好,因为我所需要做的只是向指向127.0.0.1的DNS记录添加一个CNAME。
但是,我还不能让它与IIS Express一起工作。我所做的一切努力似乎都失败了。我甚至向applicationHost添加了正确的XML配置。IIS Express的配置文件,但它似乎不能像真正安装IIS那样识别有效的条目。
<binding protocol="http" bindingInformation="*:1288:dev.example.com" />
每当我输入这一行并尝试请求http://dev.example.com:1288时,我都会收到以下消息:
错误请求-无效的主机名
有人知道我是否遗漏了什么明显的东西吗?或者IIS Express团队真的缺乏预见到这种类型的使用?
我试图将公共IP地址集成到我的工作流程中,这些答案没有帮助(我喜欢使用IDE作为IDE)。但以上这些让我找到了解决方案
(我花了大约2个小时的时间才把它与Visual Studio 2012 / Windows 8集成起来)下面是我最终得到的结果。
applicationhost。C:\Users\usr\Documents\IISExpress\config
<site name="MySite" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\usr\Documents\Visual Studio 2012\Projects\MySite" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:8081:localhost" />
<binding protocol="http" bindingInformation="*:8082:localhost" />
<binding protocol="http" bindingInformation="*:8083:192.168.2.102" />
</bindings>
</site>
设置IISExpress以管理员身份运行,以便它可以绑定到外部地址(而不是本地主机)
以管理员身份运行Visual studio,这样它就可以以管理员身份启动流程,从而允许发生绑定。
最终结果是,在我的例子中,您可以浏览到192.168.2.102并进行测试(例如在Android模拟器中)。我真的希望这能帮助到其他人,因为这对我来说绝对是一个恼人的过程。
显然,这是一个安全功能,我希望看到禁用。
并对该方法进行了测试。NET Core 3.1和Visual Studio 2019。
vs PROJECTNAME \配置\ applicationhost。配置
将“*:44320:localhost”修改为“*:44320:*”。
<bindings>
<binding protocol="http" bindingInformation="*:5737:localhost" />
<binding protocol="https" bindingInformation="*:44320:*" />
</bindings>
这两个链接都有效:
https://localhost:44320
https://127.0.0.1:44320
现在,如果你想让应用程序与自定义域一起工作,只需要在主机文件中添加以下一行:
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 customdomain
Now:
https://customdomain:44320
注意:如果你的应用在没有SSL的情况下工作,请更改protocol="http"部分。