Click here to Skip to main content
15,886,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

 
Share this answer
 
Comments
Advay Pandya 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
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.
 
Share this answer
 
v2
Comments
Advay Pandya 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 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 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 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900