1

I have a .NET 6 Blazor Server and another .NET 6 Blazor Wasm site. Both work fine locally but when hosted on a shared hosting site get an error 'too many redirects'. I can't change any setup on the shared hosting so am restricted to web.config & source startup code.

After investigation, the startup code in program.cs

app.UseHttpsRedirection();

is causing the issue. If I comment that out the application works, but if you use an http address it doesn't get redirected to https - so no good. This all happened after I had to set web.config to use out of process hosting model (required by shared hosting when using multiple apps).

<aspNetCore processPath="dotnet" 
    hostingModel="outofprocess" ...

This question was very helpful in discovering the issue. The same site produces "too many redirects" only via cellular, not via WiFi. I also tried forwarding headers as in https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-6.0, but nothings helps.

I'm out of things to try. Any suggestions would be appreciated.

Craig
  • 517
  • 1
  • 9
  • 17
  • Why not post the detailed network redirect requests from your browser's developer tools to see what is redirecting to what? – Uwe Keim Mar 31 '22 at 10:21
  • @Uwe Keim - I don't think he'll see anything in his browser's developer tools. I've seen this before, it's the host redirecting it to http, and blazor redirecting it back to https, causing it to loop... Where are you hosting this? AWS or Azure or... Cause how to fix it kinda depends on the host – Ron Sijm Mar 31 '22 at 18:47
  • Hi, it's on IONOS shared windows hosting. And yes that's looks like what's happening. – Craig Mar 31 '22 at 21:43
  • Did you tried to host some other server other than `IONOS` or could capture the logs for that? – Md Farid Uddin Kiron Apr 01 '22 at 08:14
  • no IONOS is all I have. – Craig Apr 01 '22 at 08:17
  • @Uwe Keim - browser tools just show each Get request as the same. Request URL is https, status code 307, response header shows location as https – Craig Apr 01 '22 at 09:41
  • Can anyone offer a suggestion here? My only way forward seems to be to dump the Shared hosting solution if the redirection issue cannot be solved. Has anyone had success with 2 Blazor sites (therefore outofprocess model) on a shared hosting solution with SSL redirects working ok? – Craig Apr 04 '22 at 15:09
  • So you would also want to redirect `http address` as well right? – Md Farid Uddin Kiron Apr 07 '22 at 02:09
  • Yes I which I believe is normally handled via app.UseHttpsRedirection();. I assume this is a specific shared hosting style issue. But one there should be a way around. – Craig Apr 07 '22 at 08:40

1 Answers1

0

I had the same issue. Turned out IONOS (1and1 / 1und1) is using Apache as proxy (I have Windows hosting). So you can use a .htaccess file to redirect to https, like:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [L,R=301]

BUT this is only half the way. Websockets do also not work because of the proxy and I still haven't found a solution for that.

Sven
  • 11,442
  • 2
  • 16
  • 20
  • yep, I tried the .htaccess & it worked. Same WebSockets issue. IONOS not really helping - blaming my ISP for redirects & IPV6. – Craig May 16 '22 at 14:16