Monday, June 24, 2019

Action Filter in MVC

1.


     
    public class change_all_form_authorization : ActionFilterAttribute
    { 
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string controller_ = filterContext.RouteData.Values["controller"].ToString();
            string action_ = filterContext.RouteData.Values["action"].ToString();

            if (HttpContext.Current.Session["change_all_form_authorization"] == null)
            {
                HttpContext.Current.Session["change_all_form_authorization"] = "/" + controller_ + "/" + action_;
                //HttpContext.Current.Session["change_all_form_authorization"] = "authorize-form-password";
                filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new
                {
                    Controller = "Login",
                    Action = "auth_form_permi"
                }));
                //HttpContext.Current.Response.Redirect("/Login/auth_form_permi");
                return;
            }
            HttpContext.Current.Session["change_all_form_authorization"] = null;
            base.OnActionExecuting(filterContext);
        }
    }

No comments:

Post a Comment

Linq Expression syntax for where condtion in linq

(Expression<Func<T, bool>> filter)