I can’t seem to redirect from the Application_BeginRequest in my asp.net mvc site. I’m not sure why this isn’t working… I suspect routing, but not exactly sure why.
/// <summary>
/// Application_BeginRequest
/// </summary>
protected void Application_BeginRequest(object sender, EventArgs e)
{
Response.Redirect("siteoffline.html");
}
Firefox display this message when I try
The page isn't redirecting properly
Firefox has detected that the server is redirecting the
request for this address in a way that will never complete.
You are redirecting inside
Application_BeginRequestwhich is invoked for each request. So when your application runsApplication_BeginRequestis triggered and you redirect tositeoffline.htmland when this page is served,Application_BeginRequestis triggered and you redirect tositeoffline.htmland you get the point of the infinite loop. Fortunately FireFox stops this madness after it detects that you are abusing too much with redirects.Conclusion: never redirect to a page that is part of your web site inside the
Application_BeginRequestevent, it’s like shooting yourself into the foot.By the way for putting your site in maintenance mode you probably want to use an app_offline.htm file as blogged by the Gu instead of reinventing wheels.