I have implemented my login page and it works fine, but I cannot read from the ReturnUrl query string parameter that holds the original requested URL.
For example, when successfully logging in from this page:
http://whatever/Login.aspx?ReturnUrl=%2fAdmin%2fmenu-link.aspx
I get the following:
Context.Request.QueryString["ReturnUrl"] = null
Context.Request.Params["ReturnUrl"] = null
Context.Request.Url.ToString() = "http://localhost/Login.aspx"
UrlReferrer = "http://localhost/Login.aspx?ReturnUrl=/Admin/menu-link.aspx"
Why does this happen?
Thanks for the answers but I don’t use Session State on this particular website so it is not an option for me. The first time the user is redirected to the login page (after accessing a restricted page), I can correctly see the query string in the page_load, however it gets lost on postback.
Here is my page code, I don’t know why it isn’t persisting:
<body>
<form id="form1" action="Login.aspx" runat="server" defaultbutton="btnLogin">
//Bunch of html
<asp:Button TabIndex="5" CausesValidation="true" runat="server" ID="btnLogin" Text="Log In" onclick="btnLogin_Click" /></div>
</div>
</form>
</body>
Your
formis not preserving thequerystringwhen the login button is submitted, as such it appears in the UrlReferrer.Save the querystring to a session variable or append the query string to the
formactionattribute.