Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET url
Hi all
 
I want to restrict user to enter direct url.
 
If user tries to enter url then it should redirect back to the last page that the user visited.

 
I used Request.ServerVariables["HTTP_REFERER"] . When user enters direct url then it returns "Null".
 
So I can get , user entered direct url
 
But how to redirect the user to the last page he/she visited ?
 
Is there any preferable alternative way to implement this ?
 
Please advise.
 
Thanks
 
Advay Pandya
Posted 2-Jul-12 23:29pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Advay Pandya at 3-Jul-12 5:39am
   
Hi Prasad,
Thanks for your solution.
 
But both links suggest to redirect page into login or some other AccessDenied page, I dont want to kill session or redirect user into any other page. I want user to stay in the same page.
 
ex. If user is in a.aspx page, and if they try to change url to b.aspx , then user should stay in a.aspx
 
When user change url directly then all the dot net objects which are used to get previous page url are getting refreshed. And they returns NULL value.
 
So how can I achieve this ?
 
Thanks
Advay Pandya
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
I used Request.ServerVariables["HTTP_REFERER"] . When user enters direct url then it returns "Null".
 
i don't know about ServerVariables. thanks for the information.
 
for getting previous page URL please Refer this link[^]
 
hope this will help you
 
thanks
-Amit.
  Permalink  
v2
Comments
Advay Pandya at 3-Jul-12 5:42am
   
Hi Amit,
 
Thanks for your suggestion.
 
I tried this solution from my end.
 
But , when user change url directly then all the dot net objects which are used to get previous page url are getting refreshed. And they returns NULL value. So in this case I am not able to get the previous page information.
 
Please advise if you have any other idea.
 
Thanks
Advay Pandya
amitgajjar at 3-Jul-12 5:56am
   
ok... in that case you can store last visited page in cookies and if you found ServerVariable as null then read the cookies and redirect on that page. is that cool ? or you want any other alternative ?
amitgajjar at 3-Jul-12 5:57am
   
What i have seen in other web application is when user manually enter incorrect URL, they are redirected on the home page. this is just for your information. i know you do not have such requirement.
Advay Pandya at 3-Jul-12 7:25am
   
I have already keep this solution in my mind to store last visited page in session or cookies. But I am looking for other alternative. I am looking for default function or object. Session or cookies may affect performance of the application.
If you have any other alternative or any idea related to this then please share with me.
amitgajjar at 3-Jul-12 7:33am
   
if user enter URL manually there will not be any information for the previous page as it is new request. so you need to store something to redirect on the previous page. if you would like to redirect on home page then you do not need to keep cookies or session variable.
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 320
1 OriginalGriff 155
2 Peter Leow 115
3 Afzaal Ahmad Zeeshan 114
4 deepakdynamite 110
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,994
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100