Original translated from: http://www.cnblogs.com/yicone/archive/2008/05/22/1204431.html
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:
But soon we found that this would cause a runtime error:
In the ApplicationProgramIt is incorrect to use the Section registered as allowdefinition = 'machinetoapplication' outside of the level.
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>