How do you read a parameter from the URL?

I am trying to use the login.aspx page in such a way that when a
user tries to access any given page, it will redirect them to the login screen
if they are not authenticated and after a successful authentication go back to
the page they were trying to access. My issue is that when I go to the page and
get redirected, I don’t go back to the page I came from. Here is a sample of
what my login.aspx page has for an URL:

http://localhost/Login.aspx?ReturnUrl=/OtherPage.aspx

As you can tell, ASP.Net is smart enough to include the return to
URL, however, how can I make use of that to redirect my users back to that page? Also, in general, how can you read a parameter in the URL query string?

Thanks!


The following code would address the issue. Note that you can read any Paramater by doing a QueryString from the Request. ReturnUrl is the one that pertains to this particular example:

if (Request.QueryString["ReturnUrl"] != null)

{

string ReturnUrl = Request.QueryString["ReturnUrl"].Trim();

//Navigate to the ReturnUrl

}

else

//Navigate to a specific home page

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.