使用RequireHttpsAttribute ASP.NET Core的HTTP错误310 ERR_TOO_MANY_REDIRECTS

我正在使用MVC在ASP.NET核心上构建一个应用程序。 我也在我的应用程序中使用Identity和Entity 7框架。 我正在Microsoft Azure上运行应用程序,该应用程序应附带HTTPS证书。

我正在使用此代码在我的Startup.cs中启用HTTPS

services.AddMvc(options => { #if !DEBUG options.Filters.Add(new RequireHttpsAttribute()); #endif }); 

我的问题是,当我访问网络应用程序时,我得到一个310 HTTP ERR_TOO_MANY_REDIRECTS响应。 我已经尝试清除我的cookie并将Web应用程序重新发布到Azure,但这些都没有成功。

当我禁用上面的代码时,我的应用程序在Azure上运行。 当我在浏览器中手动键入https://时,我得到一个安全的HTTPS连接。

我的应用程序遇到了同样的问题。

请检查您的Startup.cs Configure方法。 在那里你应该包括app.UseIISPlatformHandler();

 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app) { ..... app.UseIISPlatformHandler(); ..... } 

RequireHttpsAttribute使用此IISPlatformHandler在您的网站上启用HTTPS。