我面临与another question相关的困境,但不完全相同。
我想将IIS Express与自定义网址一起使用,但而不修改本地HOSTS文件。
具体来说,对我来说,dev.example.com
使用DNS解析为127.0.0.1(我们的DNS设置为*.example.com
解析为127.0.0.1)。这就是我想用作项目URL的内容。如果我将dev.example.com
添加到我的HOSTS文件中,它会起作用,但如果我不这样做,它就不会。我猜测这是因为Visual Studio不会将此识别为本地URL。
有没有办法不修改HOSTS文件,但仍然使用像dev.example.com
这样的自定义URL作为Visual Studio和IIS Express中的项目URL?
答案 0 :(得分:3)
是 - sortof。 IISExpress
配置存储在执行用户配置文件中:
C:\Users\<username>\Documents\IISExpress\config\
您需要修改 applicationhost.xml
找到<sites>
部分并展开:
<site name="WebApplication1" id="20">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\inetpub\WebApplication1" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:45965:localhost" />
<binding protocol="http" bindingInformation="*:80:dev.example.com" />
</bindings>
</site>
请注意,如果IIS在开发框中运行,则不得占用端口80。
此解决方案面临的问题是,使用这些设置在VS中按F5,或以其他方式从VS启动网站将始终要在localhost上启动,并且不会初始化其他绑定。您必须使用以下命令手动启动IISExpress:
c:\ Program Files(x86)\ IIS Express \ iisexpress.exe“/ site:WebApplication1