当我调试Visual Studio项目使用Chrome浏览器尝试重定向到https相当于我的web地址。我没有在web项目中启用SSL,并且开始URL是http URL。当我使用FireFox或IE进行调试时,我没有这个问题。

我重新安装了Chrome浏览器,解决了这个问题一天。没有下载任何插件的问题再次发生了第二天。

什么是使Chrome重定向localhost到https?

网络巡检显示: 请求URL:数据:text / html, chromewebdata 请求头 显示临时标题 User-Agent:Mozilla/5.0 (Windows NT 6.3;WOW64) AppleWebKit/537.36 (KHTML,像Gecko) Chrome/36.0.1985.143 Safari/537.36

这些选项卡中没有预览和响应数据。


当前回答

The issue could be replicated in VS 2019 also. This is caused due to "Enable Javascript debugging from Visual Studio IDE". The VS attaches to Chrome and it is a possibility that due to security or reasons known to Google and Microsoft, it sometimes fails to attach and you have this issue. I am able to run http and https with localhost from ASP net core 3.1 app. So while debugging in VS, go to the run with arrow -> IIS express, just below "Web Browser(Chrome)" select "Script Debugging (Disabled)".

参见文章:https://devblogs.microsoft.com/aspnet/client-side-debugging-of-asp-net-projects-in-google-chrome/

https://learn.microsoft.com/en-us/visualstudio/debugger/debugging-web-applications?view=vs-2019

总是退回到微软文档,以获得比谷歌更清楚的问题。

其他回答

Chrome 63(自2017年12月发布)将强制所有以。dev(和。foo)结尾的域通过预加载的HTTP严格传输安全(HSTS)头重定向到HTTPS。你可以在这里找到更多信息。

这些对我都没用。它开始发生在chrome更新(版本63.0.3239.84,linux)与一个本地URL。无论如何都会重定向到https。我在这上面浪费了很多时间和耐心

最终起作用的只是改变定义域。

不管怎样,域名是。app。也许是有什么事?只是把它改为。test和chrome停止重定向它

对于像我这样在本地主机上运行Node.js express服务器的人来说,我有这段代码可以将http重定向到https:

const server = express() 
  .use((req, res, next) => {
    if (req.headers['x-forwarded-proto'] != 'https') {
      res.redirect('https://' + req.headers.host + req.url)
    } else {
      next()
    }
  })

你必须确保它不会重定向localhost:

const server = express() 
  .use((req, res, next) => {
    if (req.headers['x-forwarded-proto'] != 'https' && req.headers['host'].indexOf("localhost") == -1) {
      res.redirect('https://' + req.headers.host + req.url)
    } else {
      next()
    }
  })

对于有同样问题的人,我通过按CTRL + SHIFT + DELETE删除整个浏览器缓存来解决。现在我可以在HTTP协议上访问我的本地主机网站。

新发展!(如果你有Chrome 63+)

如果您的本地主机域是.dev,那么我认为之前接受的答案是行不通的。原因是因为自Chrome 63以来,Chrome将通过预加载的HSTS强制。dev域使用HTTPS。

这意味着,.dev基本上不能再工作了,除非您有适当的签名SSL证书——不允许有自签名证书!在这篇博客文章中了解更多。

因此,现在要修复这个问题,并避免这种情况在未来再次发生。test是一个推荐的域名,因为它是由IETF保留用于测试/开发目的。您还应该能够将.localhost用于本地开发。