Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert,

I am Uday Satardekar,
I am developing asp.net website.

In my website there are some pages like edit_user.aspx,add_new_user.aspx.

This facility available only for admin.

I store usertype in session.and checking like this,

if (Convert.ToInt64(Session["usertype"]) == 1)


Here 1 for admin and 2 for other user.

then how to restrict these pages from other user.
Posted
Updated 19-Oct-11 22:27pm
v2

Well here you will find a nice tutorial that will guide you in implementing ASP.NET Membership, Roles and Profile provider.

http://www.4guysfromrolla.com/articles/120705-1.aspx[^]

Once you are using a technique like this, it is very easy to do so. Inside the folder that contains the pages that you would like to restrict the access just put in a proper web.config file specifying the access rights.

You can also take a look on this video.

http://www.asp.net/general/videos/lesson-9-securing-your-web-site-with-membership-and-login-controls[^]


Cheers
 
Share this answer
 
Comments
BobJanova 19-Oct-11 7:02am    
5 for this. Doing it properly with roles and access control is what should happen.
udusat13 19-Oct-11 7:28am    
Thankssssss.....
Mario Majčica 19-Oct-11 7:30am    
If helpful accept the answer and eventually vote it! Cheers!
In Page load event of both edit_user.aspx and add_new_user.aspx pages

Write the code like this

if (Convert.ToInt64(Session["usertype"]) == 1)
{
//Write the code

}

else
{
//Put a message like "you are not Authorized to see these pages"
//or
//Redirect to login page
}
 
Share this answer
 
Comments
udusat13 19-Oct-11 7:09am    
Thanks for suggestion........

But for this code can i use (!IsPostBack) or i have directly insert it into page load....
AmarSinghRawat 20-Oct-11 5:35am    
You can write it directly into page load. because may be if are changing any user role from admin to user or user to admin then it will reflect.

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