带有.NETCore RC2的RequireHttpsAttribute导致Azure上的HTTP302重定向循环 [英] RequireHttpsAttribute with .NETCore RC2 causes HTTP302 redirect loop on Azure

查看:90
本文介绍了带有.NETCore RC2的RequireHttpsAttribute导致Azure上的HTTP302重定向循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用RequireHttpsAttribute设置在Azure上运行.NETCore RC2 Web应用程序,但是我遇到了问题。

I've been trying to get a .NETCore RC2 web app working on Azure with the RequireHttpsAttribute set but I'm having issues.

要消除以下可能性:这是我在代码中引入的一个问题,我将事情减少到最低限度,并使用现成的 VS2015 .NETCore RC2模板重新创建。

To remove the possibility of this being a problem that I've introduced with my code, I cut things back to the bare minimum and recreated it using the "out of box" VS2015 .NETCore RC2 template.

如果我部署标准的VS2015 .NETCore RC2 Web应用程序,则该站点运行良好。如果再将[RequireHttps]添加到控制器,则在本地运行良好,但在Azure上会导致HTTP302重定向循环。自RC1以来,这似乎已经发生了变化,因为RequireHttpsAttribute在Azure中可以与RC1一起很好地工作。

If I deploy the standard VS2015 .NETCore RC2 web app the site runs fine. If I then add [RequireHttps] to the controllers it works fine locally, but on Azure it causes an HTTP302 redirect loop. This seems to be something which has changed since RC1 since the RequireHttpsAttribute works fine in Azure with RC1.

这里有一个类似的问题:带有RequireHttpsAttribute ASP.NET Core的HTTP错误310 ERR_TOO_MANY_REDIRECTS ,但是尚不清楚该问题是在谈论RC1还是RC2(我实际上是在怀疑RC2),但是唯一的答案仅适用于RC1。

There is a similar question here: HTTP Error 310 ERR_TOO_MANY_REDIRECTS with RequireHttpsAttribute ASP.NET Core, but it's not clear if the question is talking about RC1 or RC2 (I actually suspect RC2), however the only answer is only applicable for RC1.

关于此属性会在AWS上导致重定向循环: RequireHttps会导致重定向循环

There is a similar question about this attribute causing a redirect loop on AWS here: RequireHttps causes redirect loop on Amazon Elastic Load Balancer but that is MVC4 and also mentions a header which isn't used by Azure.

推荐答案

当前有一个 bug 在Azure和ASP.NET Core RC2中,这与Kestrel和IIS的连接方式以及HTTPS标头(表明是否为HTTPS请求)有关。

There's currently a bug in Azure and ASP.NET Core RC2 which relates to how Kestrel and IIS are connected and the HTTPS header that says that it's an HTTPS request or not.

我知道由于错误被标记为完成,因此它可能很快就会在RTM上得到解决。

I understand that it might get solved soon on RTM since the bug is marked as Done.

我们所做的解决方法使用 web.config 从任何HTTP请求进行永久重定向到HTTPS。我们使用 dotnet-transform 包在仅发布(因此,在本地开发环境(不适用于)。这是可选的,如果您需要它作为FYI。

A workaround we did is to use web.config to make a permanent redirect from any HTTP request to HTTPS. We use the dotnet-transform package to insert the redirect on Publish only (so locally on a dev environment it doesn't apply). This is optional if you need it as a FYI.

这篇关于带有.NETCore RC2的RequireHttpsAttribute导致Azure上的HTTP302重定向循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆