. Net Core MVC Filter (i)

Source: Internet
Author: User

1. Filter filter runs in MVC action invocation Pipeline (MVC Action request pipeline), we call it filter Pipleline (filter pipeline), filter pipleline Run before the MVC selection action executes, so we can do some processing before the action executes, for example: permissions. Request Order 2. Filter type each filter is executed at different stages of the filter pipleline.
    • The Authorization filters (permission filter) authorzation filters is run first in the filter Pipleline and is used to determine whether the current user has requested permission. If no permission is requested to return directly.
    • The Resource Filters (Resource filter) Resource filters runs behind Authorzation, and executes after the other filters are completed later. Resource filters implements caching or other performance reasons to return. Because it runs before the model is bound, the operation here will affect the model bindings.
    • The Action filters (method filter) Action filters is called before and after the action method is executed. This can be used in methods to handle passing parameters and return results of processing methods.
    • Exception Filters (Exception filter) Exception filters is applied by the global policy to handle unhandled exceptions before any written response to the body.
    • Result filters (Result filter) result filters can be executed before the action result is executed and execution succeeds after the action is executed, using logic that must be executed around the view or format.

is the order in which the filter pipeline is executed:

Demo:https://github.com/a764578566/myfilters You can download the demo, you execute two times on the code breakpoint. The request is the action normal once the request is the action exception reference document: https:// Docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters above is a personal translation is some understanding, relatively junior, on this will also write some, if there is a mistake to welcome correct

. Net Core MVC Filter (i)

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.