RequireHttpsAttribute with .NETCore RC2 calls HTTP302 redirect loop to Azure

I am trying to get a .NETCore RC2 web application running on Azure with the RequireHttpsAttribute suite, but I'm having problems.

To eliminate the possibility that this is a problem that I presented with my code, I reduced everything to a minimum and recreated it using the VS2015.NETCore RC2 template “out of the box”.

If I deploy the standard VS2015.NETCore RC2 web application, the site works fine. If I add [RequireHttps] to the controllers, it works fine locally, but on Azure it calls the HTTP302 redirect loop. This is similar to what has changed since RC1, since RequireHttpsAttribute works fine in Azure with RC1.

There is a similar question here: HTTP Error 310 ERR_TOO_MANY_REDIRECTS with RequireHttpsAttribute ASP.NET Core , but it is unclear whether it is worth talking about RC1 or RC2 (I actually suspect RC2), however the only answer applies only to RC1.

A similar question about this attribute causes the redirect loop to AWS: RequireHttps calls the redirect loop to Amazon's elastic load balancer , but this is MVC4 and also mentions a header that is not used by Azure.

+1
source share
2 answers

There is currently a bug in Azure and ASP.NET Core RC2 that is related to the Kestrel and IIS connection and the HTTPS header, which states that this is an HTTPS request or not.

I understand that it can be resolved soon in RTM as the error is marked as Done.

A workaround we used web.config to do a constant redirect from any HTTP request to HTTPS. We use the dotnet-transform package to insert redirection only in the publication (so that it does not apply locally in the dev environment). This is optional if you need it as FYI.

+3
source

You can get around this by adding the following lines to ConfigureServices in Startup.cs (and add "using Microsoft.AspNetCore.HttpOverrides;")

services.Configure<ForwardedHeadersOptions>(options => { options.ForwardedHeaders = ForwardedHeaders.XForwardedProto; }); 
+1
source

Source: https://habr.com/ru/post/923874/


All Articles