Method One: 1. Create a Global action filter (register filters in AppStart's filterconfig. ADD (New Loginattribute ());)
2. Contoller or action that does not require login
The filter attribute is added to the class or action (Isneed=false)
Method Two: 1. Create a filter that is not registered globally
2. Create a Basecontroler, and then add the filter attribute Basecontroller top
3. Login required to inherit the Basecontroller, do not need to log on to inherit the Basecontroller
Add: If you do not want to build basecontroler, how can be directly on the controller controllers or the action method to add a custom filter
Note: In 1.OnActionExecuting, base. OnActionExecuting (Filtercontext);
If there is more than one filter in the current project, add base. OnActionExecuting (Filtercontext);
No additional filter is performed without adding
2.filtercontext.result = new Redirectresult ("/user/login");
In the filter inside the page jumps with filtercontext.result = new Redirectresult ("/user/login");
If using FilterContext.HttpContext.Response.Redirect ("/user/login"); After the jump, you will continue to perform the action behind it.
Eg:home/index Jump User/login, will continue to execute index/action inside the method
Action Validation login in MVC (ActionFilterAttribute)