Reputation: 5489
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.
Upvotes: 3
Views: 2872
Reputation: 3593
I realize that this is old. But in my case this was due to an error in the code.
To get the real error to show I had to change this in the web.config
<customErrors mode="RemoteOnly" defaultRedirect="/Error/Index" />
To this
<customErrors mode="Off" />
It then showed me that
Upvotes: -1
Reputation: 17182
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();
}
}
Upvotes: 3