I need to implement the following custom action filter:
An action filter applied to an action CountRowsshould OnActionExecutinghander in it to βrememberβ the action that it was called earlier and redirect the client browser to the action Login, for example. But the login action must somehow find out the original action that was triggered, so that after the login is completed, it will immediately redirect back to CountRows.
CountRows
OnActionExecuting
Login
I suppose I can save the name of the source action name in filterContext TempData, but how do I implement the script?
filterContext
TempData
. , SignIn GET string returnUrl. filterContext.HttpContext.Request.RawUrl . URL . , POST, auth Redirect (model.ReturnUrl).
MVC , [Authorize]. Request.Url.Path, RawUrl, .
:
[AttributeUsage(AttributeTargets.All)] public class MyActionFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { //write your logic RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary(); redirectTargetDictionary.Add("area", ""); redirectTargetDictionary.Add("action", "Error"); redirectTargetDictionary.Add("controller", "Home"); filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary); } }
MyActionFilter "~//".
( ) : http://www.c-sharpcorner.com/UploadFile/ff2f08/use-of-mvc-custom-action-filter/