我正在使用 MVC 在 ASP.NET core 上构建一个应用程序。我还在我的应用程序中使用 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 使用此 IISlatformHandler 在您的网站上启用 HTTPS。
关于c# - HTTP 错误 310 ERR_TOO_MANY_REDIRECTS 与 RequireHttpsAttribute ASP.NET Core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37745874/