ASP. NET in the AcquireRequestState event to determine the login verification.

Source: Internet
Author: User

Add the AcquireRequestState event to global.

protected voidApplication_acquirerequeststate (Objectsender, EventArgs e) {Uri URL= Request.url;//gets the URL of the current request//access to the Admin directory requires login verification.     if(URL.) Absolutepath.tolower (). StartsWith ("/admin"))    {        //if Login.aspx is written in the admin directory, you need to exclude login.aspx authentication.         if(httpcontext.current.session["Name"] ==NULL) {HttpContext.Current.Response.Redirect ("~/login.aspx"); }    }}

You can also use the IHttpModule interface to create a class that is called under the configuration file.

Don't forget: Configure it in the configuration file.
<add name= "Checkadminmodule" type= "Web.Common.CheckAdminModule"/>

 Public classcheckadminmodule:ihttpmodule{ Public voidInit (HttpApplication context) {context. AcquireRequestState+=NewEventHandler (onacquirerequeststate); }   Public voidOnacquirerequeststate (Objectsender, EventArgs e) {HttpApplication application= Sender asHttpApplication; Uri URL= Application. Request.url;//gets the URL of the current request//access to the Admin directory requires login verification.     if(URL.) Absolutepath.tolower (). StartsWith ("/admin"))    {      //if Login.aspx is written in the admin directory, you need to exclude login.aspx authentication.       if(Application. session["Name"] ==NULL) //httpcontext.current.session["Name"]  {application. Response.Redirect ("~/login.aspx"); }    }  }}

The

ASP. NET determines the login validation in the AcquireRequestState event.

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.