The website structure is as follows:
/Default. aspx
/Login. aspx
/Adminlogin. aspx
/Member/*. aspx
/Admin/*. aspx
Requirement: Requests to access pages in the/member/path are redirected to/login. aspx;
The request to access the page in the/admin/path is redirected to/adminlogin. aspx;
In the beginning, you can configure/Web. config as follows:
<System. web>
<Authentication mode = "Forms">
<Forms loginUrl = "/Login. aspx" name = ". ASPXFORMSAUTH">
</Forms>
</Authentication>
</System. web>
<Location path = "member">
<System. web>
<Authorization>
<Deny users = "? "/>
</Authorization>
</System. web>
</Location>
<Location path = "admin">
<System. web>
<Authentication mode = "Forms">
<Forms loginUrl = "/AdminLogin. aspx" name = ". ASPXFORMSAUTH">
</Forms>
</Authentication>
<Authorization>
<Deny users = "? "/>
</Authorization>
</System. web>
</Location>
But soon we found that this would cause a runtime error:
The Section registered as allowDefinition = 'machinetoapplication' outside the application level is incorrect.
Google has encountered many similar errors, but there are not many similar problems. Therefore, a flexible approach was adopted temporarily (eager to solve the problem, there may be a good/better solution ). Two steps:
1. Define/LoginHandler. ashx. In the ProcessRequest method,
If (! HttpContext. Current. User. Identity. IsAuthenticated ){
String loginUrl;
String returnUrl = context. Request. Params ["returnUrl"];
If (returnUrl. Contains ("/Admin /")){
LoginUrl = "/AdminLogin. aspx ";
}
Else {
LoginUrl = "/Public/Login. aspx ";
}
If (! String. IsNullOrEmpty (context. Request. Params ["returnUrl"]) {
LoginUrl = loginUrl + "? ReturnUrl = "+ HttpUtility. UrlEncode (context. Request. Params [" returnUrl "]);
}
Context. Response. Redirect (loginUrl );
}
2. Configure/Web. config,
<System. web>
<Authentication mode = "Forms">
<Forms loginUrl = "/LoginHandler. ashx" name = ". ASPXFORMSAUTH">
</Forms>
</Authentication>
</System. web>
<Location path = "LoginHandler. ashx">
<System. web>
<HttpHandlers>
<Add verb = "*" path = "LoginHandler. ashx" type = "Web. LoginHandler" validate = "true"/>
</HttpHandlers>
</System. web>
</Location>
<Location path = "member">
<System. web>
<Authorization>
<Deny users = "? "/>
</Authorization>
</System. web>
</Location>
<Location path = "admin">
<System. web>
<Authorization>
<Deny users = "? "/>
</Authorization>
</System. web>
</Location>