I am using asp.net mvc 3 for developing web application.
I have written custom global Action filter which is getting triggered whenever I am invoking any of the pages in mvc site.
In that filter, I am checking certain conditions, if those conditions are met, I am redirecting user to "unavailable" page. It is working fine in all cases expect one.
It is not working on Home/Index, which is my default route. When I first launch the application I can see Home/Index in fiddler with status code 302 (redirect to application/unavailable).
Browser then tries to redirect to application/unavailable page. To my surprise I can see 302 in fiddler from this page again to Home/Index. This keeps continue till some time and then I am getting below error in Firefox
"Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
I can see that there is infinite loop of 302 in fiddler. But I don't know why it is happening. Am I doing something wrong in routing?
My code working for other pages of website.
Here is my code:
routes.MapRoute("Application", "Application/Unavailable", MVC.Application.Unavailable());
routes.MapRoute("Home", "Home/{action}", new {controller = "Home"}, new[] {"Test.Web.Controllers"});
routes.MapRoute("Default", "{controller}/{action}", MVC.Home.Index(), new[] {"Test.Web.Controllers"});
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
...
...
if (conditionmet)
{
RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
redirectTargetDictionary.Add("area", "");
redirectTargetDictionary.Add("action", "Unavailable");
redirectTargetDictionary.Add("controller", "Application");
filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary);
}
}