Howto: enables ASP. NET Website Forms authentication to specify multiple logon pages

Source: Internet
Author: User

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> 
Related Article

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.