I have a problem with an ActionFilterAttriute that is not redirecting correctly. I'm not familiar with the complete codebase, but I have seen enough to not understand what is going on.
To simplyfy the code, I have removed the irrelevant parts:
public class ResolveApplicationRedirectAttribute : ActionFilterAttribute
{
//some variables
private ActionExecutingContext _filterContext;
protected string ApplicationRedirectUrl
{
get { return ConfigurationManager.AppSettings["ApplicationRedirectUrl"]; }
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
_filterContext = filterContext;
//a lot of logic that decide if we should redirect or not
//I added this after the other logic to make it always redirect regardless of what happens inside the logic above
_filterContext.Result = new RedirectResult(ApplicationRedirectResult);
}
}
[ResolveApplicationRedirect]
public ActionResult Index(CrmQueryStringParameters crmParameters){
//some logic
}
This usually works, but when the application gets hit by a few requests in a short period of time, the Index method ends up being called, and blows up because the View is missing some data (we know it's missing data. That is why we want to redirect).
But Now when I have added the _filterContext.Result = new RedirectResult(ApplicationRedirectResult)
as the last line of the OnActionExecuting
method, how is it possible that it still calls my Action method?
Are there any knows bugs/corner cases/anything else that can cause MVC to disregard the RedirectResult
I have put into the filterContext
and fire the action method anyway?
Anything special that can be inside the logic of OnActionExecuting that can cause problems even if I set the filterContext.Result as the last line. Any exceptions inside the attribute should just blow it up, and not skip the attribute and call the Action method.
Any help to point me in the right direction would be appreciated here.