What is the best way to do a redirect in an ActionFilterAttribute. I have an ActionFilterAttribute called IsAuthenticatedAttributeFilter and that checked the value of a session variable. If the variable is false, I want the application to redirect to the login page. I would prefer to redirect using the route name SystemLogin however any redirect method at this point would be fine.
What is the best way to do a redirect in an ActionFilterAttribute . I
Share
Set filterContext.Result
With the route name:
You can also do something like:
If you want to use
RedirectToAction:You could make a public
RedirectToActionmethod on your controller (preferably on its base controller) that simply calls the protectedRedirectToActionfromSystem.Web.Mvc.Controller. Adding this method allows for a public call to yourRedirectToActionfrom the filter.Then your filter would look something like: