locked
programmatically return user back to current page on login RRS feed

  • Question

  • User1909155429 posted

    To open my page users need to login. 
    What happens is users click button to open page in the modal dialog. when not logged in the login page appears inside modal window and remains open once user authenticated

    and current page shown in new modal window on top of the login window ? 

     I need to either close login page after authentication process or else programmatically redirect user back to current page after login from code:

    Using the aforementioned script does not return back to current page.

    Protected Sub ButtonPopup_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonPopup.Click

      If User.Identity.IsAuthenticated = False Then

    Response.Redirect("~/Project/Authenticate/Login.aspx")

    End If

       Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopUp", "window.showModalDialog('..\Project\Details.aspx', 'test', 'dialogWidth:830px;dialogHeight:800px;resizable:no;scrollbars:no'); ", True)


    End Sub

    Tuesday, July 15, 2014 9:07 AM

Answers

  • User465171450 posted

    You do this by passing a parameter to your login page such as ReturnUrl. That's what the standard membership systems do. That way you can then check to see if there is a querystring variable for ReturnUrl (or whatever you choose) and use that to redirect back. You can try:

    Response.Redirect(ResolveUrl("~/Project/Authenticate/Login.aspx") + "?ReturnUrl=" + Server.UrlEncode(Request.Url.AbsolutePath));

    and in the login

    if(Request.QueryString["ReturnUrl"] != null)
    {
       Response.Redirect(Server.UrlDecode(Request.QueryString["ReturnUrl"]));
    }
    else
    {
     // redirect wherever.
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 15, 2014 12:57 PM

All replies

  • User465171450 posted

    You do this by passing a parameter to your login page such as ReturnUrl. That's what the standard membership systems do. That way you can then check to see if there is a querystring variable for ReturnUrl (or whatever you choose) and use that to redirect back. You can try:

    Response.Redirect(ResolveUrl("~/Project/Authenticate/Login.aspx") + "?ReturnUrl=" + Server.UrlEncode(Request.Url.AbsolutePath));

    and in the login

    if(Request.QueryString["ReturnUrl"] != null)
    {
       Response.Redirect(Server.UrlDecode(Request.QueryString["ReturnUrl"]));
    }
    else
    {
     // redirect wherever.
    }



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 15, 2014 12:57 PM
  • User1909155429 posted

    How may I append the querystring parameter value onto the path ?

    e.g

    MyProject/ProductDetails.aspx?productid=48

    Thanks

    Wednesday, July 16, 2014 12:09 PM