Question

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);
                }
}
Was it helpful?

Solution

I managed to resolve the issue. I was using form authentication in MVC site. And login url was configured as Home/Index. So When user was redirected from Home/Index to Application/Unavailable, it is redirected again to default page as user is unauthenticated.

I then added location entry in web.config for excluding Application/Unavailable page from authentication.

<location path="Application/Unavailable">
        <system.web>
            <authorization>
                <allow users="*" />
            </authorization>
        </system.web>
    </location>

And my code is now working perfectly fine for Home/Index page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top