Step1: create your action attribute
public class RedirectCustomFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// // Way-1
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Home", action = "About" }));
//filterContext.Result.ExecuteResult(filterContext.Controller.ControllerContext);
//// Way-2
//var controller = (HomeController)filterContext.Controller;
//filterContext.Result = controller.RedirectToAction("about", "home");
////base.OnActionExecuting(filterContext);
}
Not If you wat to go with Way-2 then you need to create a method inside your controller
public class HomeController : Controller
{
public new RedirectToRouteResult RedirectToAction(string action, string controller)
{
return base.RedirectToAction(action, controller);
}
[RedirectCustomFilter]
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
No comments:
Post a Comment