. NET Single Sign-on filters (filter)--"SSO"

Source: Internet
Author: User


In the exploration of. NET Single sign-on, a knowledge point is used: filter. Several common authentication:Authorization Filters, verify that the user has access to the page, Action Filter, verify that user information is present when users log in, exception handling, such as the session expires can return to the login page and so on.


First, what does the filter contain?


Filter is divided into four main types, spread over MVC, from page request to authorization, to access resources at all stages.

Authorization filters: Actions related to handling validation processing

Action filters: The start and end of action processing in the controller do intercept operations

Result filters: Processing before and after the view is rendered

Exception Filters: If an exception occurs in a request that adds a Exception filter, it will be intercepted.


Here is the order in which filter works in MVC:




Second, the filter of the small demo


Before the subsystem login permission, the filter must be filtered to see if the local cookie value can be checked for verification. The following is the code in filter:

  public class Membervalidationattribute:authorizeattribute    {public        override void Onauthorization ( AuthorizationContext filtercontext)        {            //Read user login rights and information            var membervalidation = FilterContext.HttpContext.Request.Cookies.Get ("Selfuserinfo");            If it is empty, it jumps to the login page, and if it is not empty, it returns the first requested page if            (membervalidation = = null)            {                filtercontext.result=new Redirecttorouteresult (New RouteValueDictionary                    (new {controller= "account", aciton= "LogOn"                    });                return;             }            return;                    }    }


The subsystem only needs to hit a [membervalidation] on the ActionResult to access the filter at login time.

        [Membervalidation]                Public ActionResult ChangePassword ()        {            return View ();        }

third, feel

A knowledge only for others to speak out, and understand, is the real learning. Don't think about all the things so hard, just do it.




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

. NET Single Sign-on filters (filter)--"SSO"

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.