传统上,我在本地主机开发服务器上使用自定义域。大致如下:
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团队真的缺乏预见到这种类型的使用?
我试了以上所有的方法,都没用。解决这个问题的方法是在hosts文件中添加IPv6绑定。在@David murdoch回答的第五步中,添加两行而不是一行,即:
127.0.0.1 dev.example.com
::1 dev.example.com
我通过从命令行检查$ ping localhost来计算出来,它通常返回:
来自127.0.0.1的回复:bytes=32 time<1ms TTL=128
相反,它现在返回:
回复from::1:时间<1ms
我不知道为什么,但是由于某种原因,IIS Express开始使用IPv6而不是IPv4。
并对该方法进行了测试。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"部分。
以防万一有人需要…
我的要求是:
启用SSL
自定义的域
运行在(默认)端口:443
在IISExpress中设置这个URL: http://my.customdomain.com
为了设置这个,我使用了以下设置:
项目网址:http://localhost:57400
起始URL: http://my.customdomain.com
/ .vs / {solution-name} / config / applicationhost。配置设置:
<site ...>
<application>
...
</application>
<bindings>
<binding protocol="http" bindingInformation="*:57400:" />
<binding protocol="https" bindingInformation="*:443:my.customdomain.com" />
</bindings>
</site>