Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi I am using C#, ASP.NET, VS2005. How can I prevent users from directly accessing a webpage? i.e. when a user enters - "www.google.com/thispage" the users is directed back to "www.google.com". The users can only access "www.google.com/thispage" via a link on "www.google.com". Thanks! Anyhelp is appreciated.

EDIT: I want to access a user go through the "front door"(www.google.com) and not by entering manually (www.google.com/thispage). Only by clicking a link/button on (www.google.com) then it will direct the user to (www.google.com/thispage).
Posted
Updated 29-Oct-12 21:32pm
v2

If you use Solution 1 you would never access that page. It will always redirect to www.google.com. You have to detect if user is trying access it directly. You can add QueryString(www.google.com/thispage?LinkClicked=Yes) or use Session.

If Request.QueryString("LinkClicked") != 'Yes'
{
Response.Redirect("www.google.com");
}
 
Share this answer
 
put Response.Redirect("youpageurl"); in page load event.
Like
C#
Protected Void thispage_load(object sender, eventArgs e)
{
     Response.Redirect("www.google.com");
}
 
Share this answer
 
v4
Comments
AshishChaudha 30-Oct-12 1:33am    
Please elaborate your question more. There is insufficient information.
Member 9473758 30-Oct-12 2:06am    
thanks for replying but what you given will redirect even if I access from anywhere right? I want to access a user go thru the "front door"(www.google.com) and not by entering manually (www.google.com/thispage). Only by clicking a link/button on (www.google.com) then it will direct the user to (www.google.com/thispage).

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