ActionFilterAttribute in mvc ),
Method 1: 1. Create a Global action filter (register filters. Add (new LoginAttribute () in filterconfig of appstart ());)
2. Do not need to log on to the contoller or action
Add the filter feature (isNeed = false) to this class or action)
Method 2: 1. Creating a filter is not registered globally
2. Create a baseControler and add the filter feature to the basecontroller.
3. If you need to log on, the basecontroller is inherited. If you do not need to log on, the basecontroller is not inherited.
Supplement: if you do not want to create a baseControler, you can add a custom filter to the Controller or Action method.
Note: 1. base. OnActionExecuting (filterContext) in OnActionExecuting );
If the current project has multiple filters, add base. OnActionExecuting (filterContext );
If no filter is added, other filters are not executed.
2. filterContext. Result = new RedirectResult ("/User/login ");
Go to the filter page and use filterContext. Result = new RedirectResult ("/User/login ");
If filterContext. HttpContext. Response. Redirect ("/User/login") is used, the action
Eg: after the home/index jump to user/login, the method in index/action will be executed.