Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 web pages one for login and other index.
for login 3 cols are defined in database table. name, password, and role
i want that when user loges in a session is created that saves the role of user(means it takes the role from database table for that particular user). after loging in to the index pages the role session is to be checked whether the user is user or admin. how is it possible. please help me.
Posted

try this:

When the user performs login. store this in session variable like:

session["MYROLE"]=(string)textbox1.Text;

now this session is available throught the any number of pages..


pass proper select query to database and compare the roles...
 
Share this answer
 
If you are looking for a simple solution, you can create a UserContext object with contains UserName, IsAuthenticated and Roles collection. And this can be saved to session and retrived as required. In case this entry is not present in session, can be taken as user is not logged in.

For managing roles in asp.net take a look at the folllowing article:

How To: Use Role Manager in ASP.NET 2.0[^]
 
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