ActionFilterAttribute in mvc ),

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.