I have this ActionFilter
public class AppOfflineFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.ActionDescriptor.ActionName != "AppOffLine" &&
filterContext.HttpContext.Request.UserHostName != "127.0.0.1")
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary(
new { action = "AppOffLine", Controller = "Home" }));
}
}
}
It works from the start page which is does not reside under a Area, it does not work from an area because it will redirect to /Area/Home/Appoffline instead of /Home/AppOffline
Can it be fixed?
Also is there a way of speciefing which controller / action to redirect to using Generics and strongly typed code?
If you want to use RedirectToAction : You could make a public RedirectToAction method on your controller (preferably on its base controller) that simply calls the protected RedirectToAction from System. Web. Mvc.
RedirectToRouteResult is an ActionResult that returns a Found (302), Moved Permanently (301), Temporary Redirect (307), or Permanent Redirect (308) response with a Location header. Targets a registered route. It should be used when we want to redirect to a route.
RedirectToAction(String, String, Object)Redirects to the specified action using the action name, controller name, and route dictionary.
Try assigning the area
route token to an empty string:
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new {
action = "AppOffLine",
controller = "Home",
area = ""
}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With