0

We have a ASP.NET login control in our aspx:

<asp:Login ID="LogOnControl" runat="server" OnLoginError="OnLogOnError" OnLoggedIn="OnLoggedIn">

and in OnLoggedIn we do:

protected void OnLoggedIn(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
    {
        Response.Redirect(Request.QueryString["ReturnUrl"]);
    }
}

and our ReturnUrl should be something like Default.aspx#/Projects

The problem is that all after hash is trimmed. We need to pass entire URL to server (so encode it somehow).

michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63

2 Answers2

1

Jabko87 - you cannot get values after # because it is not being sent to the server. You must develop your own mechanism to handle it.

Compare: Pass URL's with hash value for redirection

And: How to get Url Hash (#) from server side

Piotr
  • 1,155
  • 12
  • 29
0

I achieved it by defining hidden input on aspx page:

<input type="hidden" id='<%= ReturnUrlHash %>' name='<%= ReturnUrlHash %>' />

and filling it with JS:

document.getElementById('<%= ReturnUrlHash %>').value = window.location.hash;

and on server side in Logon.aspx.cs I did:

public const string ReturnUrlHash = "returnUrlHash";
protected void OnLoggedIn(object sender, EventArgs e)
{
    string returnUrl = Request.QueryString["ReturnUrl"];
    if (!string.IsNullOrEmpty(returnUrl))
    {
        if (Request.Form.AllKeys.Contains(ReturnUrlHash))
        {
            returnUrl += Request.Form[ReturnUrlHash];
        }

        Response.Redirect(returnUrl);
    }
}
michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63