Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I have a web based application developed in .net 3.5 with c#.

In my application I'm trying to not to allow the anonymous users from the tampering the url, so I'm using the following code.

HTML
if(Session["empid"]==null || Session["empid"]!=null)
{
if(Request.UrlReferrer==null)
{
//redirect to some page
}
}


I have placed the above code in the page_init of masterpage.
When the user comes without loggin in it works perfectly, when the user logs in and if clicks on some hyperlink in a page again the user is being logged out.

Is there any alternative to this problem?
Posted
Updated 28-Oct-10 3:53am
v2
Comments
Dalek Dave 28-Oct-10 9:53am    
Edited for Grammar and Syntax.

Place this config into webconfig file it will help you to protect from anonymous users

Path ="admin" is a folder of web form

XML
<location path="admin">
    <system.web>
      <authorization>
        <allow roles="admin"/>
        <deny users="*"/>
      </authorization>
    </system.web>
 
Share this answer
 
I cannot understand completely what you are trying to convey.

But I have some advise for your code.

if(Session["empid"]==null || Session["empid"]!=null)


You have written code for If it is NULL or Not NULL then why there is need to specify condition if you want to pass in any of criteria.

if(Request.UrlReferrer==null)

Value of UrlReferrer is the string of the URL from which the current page is redirected.

So If it is null then It must be the initial request.

So your code will run in the case if it is first request.

If you got some points then investigate your code further, and if not succeed then put your code snippets which is running undesirably.

Please vote and Accept Answer if it Helped.
 
Share this answer
 
SQL
Basically when we use Request.UrlReferrer and the user tampers in the address bar the page can be sent to a custom page.

but when the same code is used when clicking on a hyperlink the Request.urlreferer is becoming null and teh page is moved to the custom page again.

how to restrict this.
 
Share this answer
 

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