-
Notifications
You must be signed in to change notification settings - Fork 524
Redirect HTTP to HTTPS using ASP.NET Core RC2 #916
Comments
Are you running behind IIS? aspnet/IISIntegration#140 |
@davidfowl : Azure Web Site. I read the referenced link but that issue is for a filter right? The reason why I use a service middleware is because it will run quite early in the pipeline before the request has hit the controller. |
+1
And runs ok locally, but on Azure I get an ERR_TOO_MANY_REDIRECTS :( |
IIS and Kestrel will be communicating via http on localhost so you will keep redirecting as IIS is doing https offload. (Edit: ANCM should handle this anyway, see reply #916 (comment)) Instead add this to your <system.webServer>
<rewrite>
<rules>
<rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer> |
Yeah, https isn't being correctly forwarded in Azure web sites right now. Here's a workaround: FYI @DavidDury: your redirect logic is dropping some parts of the url. It should be more like: |
@benaadams The problem with web.config is that it applies even when we run on development. Web.config transformations are not working. How can I turn the rewrite off locally? Or make the transformations work? |
@ealsur You could try this from @nil4 https://github.com/nil4/dotnet-transform-xdt |
Thanks @guardrex , my project uses WindowsAzure.Storage package, which supports .NetStandard 1.5 but dotnet-transform-xdt supports .NetCoreApp 1.0, I'll try to sort that out and see if that project helps. |
There shouldn't be any connection or problem there. |
@ealsur I wrote I updated the readme to reflect that |
@nil4, @ealsur - tools should target netcoreapp1.0. @nil4 - it would be interesting to understand why the placeholders are not replaced if you run your xdt after publish-iis. I would think that either the Xml structure is not what publish-iis assumes or xdt uses the version in the project.json as source and overwrites the target web.config that publish-iis already fixed at the target location. |
@moozzyk spot on, thanks! In my example, xdt uses the |
+1 on web.config not working in dev. VS.net just hanges if this is in the web.config in development. This should just work. (and did in RC1) |
There is a difference between If IIS Express is using the I wonder if the |
I'm having the same problem when I use the code mentioned above to enforce HTTPS. I get "too many redirects" error in my ASP.NET Core 1.0 targeting .NET 4.6.1 Any solutions to this? Shouldn't this be a simple setting in WebApps in Azure portal? |
@ealsur Thank you for your response. I want to make sure I understand this correctly. The solution really boils down to using IIS URL Rewrite. The purpose of the dotnet-transform-xdt is to make the necessary modifications to web.config and push it onto Azure WebApp during publish. Am I getting this right? |
Thank you. I appreciate your detailed response. |
Here's what I learned while trying to do the https redirect: https://gooroo.io/GoorooTHINK/Article/16767/Https-Redirect-with-AspNet-Core-RC2-And-Kestrel-on-Windows/22784 |
Since this issue is still open, let me ask if the preferred way is to use the Rewrite Middleware in (FYI) I've been using a redirect in |
The web.config option will be more efficient, but it's not portable. The Rewrite middleware is a good portable solution. The MVC attribute is another good option. |
In RC1 I created a Service Middleware that did the redirection trick
Service:
The extension:
and then in Startup.cs
The problem is now it ends up in a redirect loop no matter if I use HTTP or HTTPS.
Any ideas how can I make this work so that if the user goes to http://localhost, he will be redirected to https://localhost or real domain.
The text was updated successfully, but these errors were encountered: