Tutorial :QueryString for redirection!


I have used a query string parameter to redirect from Page 1 to Page 2. From Page 2, i wanted to redirect it to Page 3 if Page 2 has been called from Page 1. What should be the condition to check if the querystring is used?? Please help me out!! Thanks guys!


Ram, this is my interpretation of what you wanted: if user accesses Page2 due to redirect from Page1, the user will be redirected automatically to Page3. If user accesses Page2 directly (without visiting Page1), the user will stay in Page2 (no redirect to Page3).

If this is the case, inside Page1, you can set redirect("Page2.aspx?previouspage=page1"), then in Page2, inside Page_load method, check for the querystring, if previouspage exists and equals "page1", redirect to Page3, else do nothing and Page2 will show up.


You may wish to parse the HTTP_REFERER and see if Page 2 has been called from Page 1. Basically, you would build your Page 2 redirection based on the HTTP_REFERER value. In C#, the value is available using the following:



Put something into the query string of page 2 as well, and check that.

However, you should always move to reduce the number or redirects (some browsers limit at 5 - to prevent the case where while not an exact loop, the browser will redirect for ever - if it already took a couple of redirects to get to your site, then part way through this sequence, it'll stop redirecting). In Page 1 you should redirect to Page 3. If you need something done then do it in Page 1 or Page 3, but note that this is only from the browsers perspective; if you do a server.transfer to page 2 then while the logical pattern for your code is 1 -> 2 -> 3, to the browser it looks like 1 -> 3. In this case you can also check the raw URI if you wanted to know that you had got there by coming from page 1.

Looked at from another way, a redirect is part of your UI. If the user was on page 1 to being with this should have made sense, or there's a bug in your UI. If the user ends up on page 3, then this should also have made sense, or there's a bug in your UI. Now considering this, what is the purpose from the user prespective of page 2? I'm not saying there couldn't be one (I can think of cases where multiple redirects make good sense, esp. if they are of different types, e.g. a moved-permanently followed by a see-other makes sense), but chances are it doesn't and a you could deal with part of it while keeping the flow in the server.


Maybe I am not understanding this right .. but why not redirect directly from page 1 to page 3?

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »