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.