我有两个本地应用程序正在运行:
https://localhost:44300
https://localhost:44349
当浏览器向客户端应用程序发出请求时,Identity Server cookie 被发送到客户端应用程序。
由于这在产品中不会发生,因为它们是两个不同的 URL,所以我尝试了这个 answer,其中表示将一个用作
127.0.0.1
,另一个用作 localhost
,以便复制 cookie 的方式产品已发送。
但是,当我尝试访问
https://127.0.0.1:44300
时,我得到 Bad Request - Invalid Hostname
。
我检查了
C:\Windows\System32\drivers\etc\hosts
,可以看到它有这两行:
127.0.0.1 localhost
::1 localhost
我也尝试过这个answer中的建议,但没有用。
如何使用
localhost
访问 127.0.0.1
?
我的目标是访问 URL 中的 127.0.0.1 替换 localhost。 本来我是
Bad Request - Invalid Hostname
这对我有用(Microsoft Visual Studio Professional 2022(64位)-当前-版本17.6.4)
以管理员身份运行 cmd 并运行以下命令:
netsh http add urlacl url="https://*:portnumber/" user=everyone
netsh http add urlacl url="https://localhost:portnumber/" user=everyone
备份
\.vs\config\applicationhost.config
。
编辑
\.vs\config\applicationhost.config
将其添加到应用程序的绑定部分中:
<binding protocol="https" bindingInformation="*:44300:localhost" />
<binding protocol="https" bindingInformation="*:44300:*" />
确保它按该顺序列出。
以管理员身份运行 VS,你应该能够转到
https://127.0.0.1:portnumber
。