How to remove returnurl from url?

前端 未结 10 670
梦谈多话
梦谈多话 2020-11-28 08:54

I want to remove \"returnurl=/blabla\" from address bar when a user want to access to a login required page. Because I\'m trying to redirect the user to a static page after

10条回答
  •  萌比男神i
    2020-11-28 09:18

    If you want to remove returnURL from request and redirect to specific path, you can follow this steps.

    Firstly get the current context, verify if the user is authenticated and finally redirect the current path.

      HttpContext context = HttpContext.Current;
            //verify if the user is not authenticated
            if (!context.User.Identity.IsAuthenticated)
            {
                //verify if the URL contains  ReturnUrl   
                if (context.Request.Url.ToString().Contains("ReturnUrl"))
                {
                    //redirect the current path
                    HttpContext.Current.Response.Redirect("~/login.aspx");
                }
    
            }
    

    I put this code into Page_Load method from my class Login.aspx.cs

提交回复
热议问题