Redirecting to a custom view using a custom action filter in ASP.NET MVC

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.

I suppose I can save the name of the source action name in filterContext TempData, but how do I implement the script?

+3
source share
2 answers

. , SignIn GET string returnUrl. filterContext.HttpContext.Request.RawUrl . URL . , POST, auth Redirect (model.ReturnUrl).

MVC , [Authorize]. Request.Url.Path, RawUrl, .

0

:

[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/

+4

All Articles