How to override/change FormsAuthentication LoginUrl in certain cases

前端 未结 3 582
孤城傲影
孤城傲影 2020-12-06 16:23

Is there a way to dynamically change the LoginUrl of FormsAuthentication? What I have is the whole site protected by FormsAuth, but for some pages in a sub folder, I\'d lik

3条回答
  •  孤街浪徒
    2020-12-06 17:13

    I had this problem as well and have just googled here trying to solve it then remembered had done it long ago and what I did was in the default login.aspx page in the root folder in the Page_Load event I did a redirect based on return url to my sub directory manage and its login.aspx page! You'd have to repeat the relevant bit for each sub directory.

    public void Page_Load(object sender, EventArgs e)
    {
     //check for existence of ReturnUrl in QueryString       
        //if it contains manage redirect to manage login page
        if (!String.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
        {
            if (Request.QueryString["ReturnUrl"].Contains("manage"))
            {
                Response.Redirect("manage/login.aspx");
    
            }
        } 
    }
    

提交回复
热议问题