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

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

问题描述

我一直在尝试让 .NETCore RC2 Web 应用在 Azure 上使用 RequireHttpsAttribute 集运行,但我遇到了问题.

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 在带有 RC1 的 Azure 中运行良好.

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.

这里有一个类似的问题:HTTP Error 310 ERR_TOO_MANY_REDIRECTS with RequireHttpsAttribute ASP.NET Core,但不清楚问题是在谈论 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 会导致 Amazon Elastic Load Balancer 上的重定向循环,但那是 MVC4,并且还提到了 Azure 不使用的标头.

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 包仅在 Publish 上插入重定向(因此在本地dev 环境不适用).如果您需要它作为仅供参考,这是可选的.

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天全站免登陆