Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure website redirection loop

I have an ASP.NET MVC application that runs on Windows Azure Website.

All of sudden the website started to redirect homepage URL '/' to itself causing a redirect loop. No change was made in the application at the time of the incident and log files don't contain any suspicious information - just lot of similar requests

2014-01-09 09:00:05 SITE_NAME GET / X-ARR-LOG-ID=581f1d91-727a-4820-a7fa-7c21888b5813 80 - 193.85.68.249 Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+5.1;+Trident/4.0;+Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1)+;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.4506.2152;+.NET+CLR+3.5.30729) _ga=GA1.2.720579394.1386747761;+ARRAffinity=12ae470da6bd7ab5a7c446a8f29748ba5f73605e7fcd365292d61319cb67336f;+WAWebSiteSID=654ed6b99c9747759561e52c1f2cb0f8 - www.domain.cz 301 0 0 534 1069 31
2014-01-09 09:00:05 SITE_NAME GET / X-ARR-LOG-ID=3ddebc99-c083-4cbf-9bbe-90d755a8b1a0 80 - 193.85.68.249 Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+5.1;+Trident/4.0;+Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1)+;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.4506.2152;+.NET+CLR+3.5.30729) _ga=GA1.2.720579394.1386747761;+ARRAffinity=12ae470da6bd7ab5a7c446a8f29748ba5f73605e7fcd365292d61319cb67336f;+WAWebSiteSID=654ed6b99c9747759561e52c1f2cb0f8 - www.domain.cz 301 0 0 534 1073 0

When I restarted the Azure website everything went back to the normal. The same problem occurred for the third time, so it probably isn't just a 'hiccup' of the server.

Can anybody help me with the problem diagnostic? I am kind of lost, because neither server logs nor application logs contains any useful information.

like image 897
Lukas Kabrt Avatar asked May 19 '26 05:05

Lukas Kabrt


2 Answers

You can use Application_BeginRequest to have the routing globally between non-www url to www url.

 protected void Application_BeginRequest(Object sender, EventArgs e)
 {   
   if (!Request.Url.Host.StartsWith("www"))
   {
      UriBuilder builder = new UriBuilder (Request.Url);
      builder.Host = "www." + Request.Url.Host;
      Response.Clear();
      Response.StatusCode = 301;
      Response.StatusDescription = "Moved Permanently";
      Response.AddHeader("Location", redirectUrl);
      Response.End();
   }
 }
like image 75
ramiramilu Avatar answered May 21 '26 19:05

ramiramilu


See what Microsoft has to say about it here:

http://social.msdn.microsoft.com/Forums/wpapps/en-US/ee3a5f97-8a58-4b42-a2d9-a73cd5d12c01/issues-with-redirect-rules-used-in-url-rewrite-feature?forum=windowsazurewebsitespreview

like image 35
Cort Avatar answered May 21 '26 20:05

Cort



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!