我如何创建角色会话 [英] how can i create session of role

查看:61
本文介绍了我如何创建角色会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个网页用于登录和其他索引.
在数据库表中定义了3个列的登录名.名称,密码和角色
我希望当用户登录时创建一个保存用户角色的会话(这意味着它将从数据库表中获取该特定用户的角色).登录到索引页面后,将检查角色会话是用户是user还是admin.这怎么可能.请帮助我.

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.

推荐答案

尝试一下:

用户执行登录时.将其存储在会话变量中,例如:

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

现在,该会话可以在任意数量的页面中进行..


向数据库传递适当的选择查询并比较角色...
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...


如果您正在寻找一个简单的解决方案,则可以创建一个包含UserName,IsAuthenticated和Roles集合的UserContext对象.可以将其保存到会话中,并根据需要进行检索.如果会话中不存在此条目,则可以视为未登录用户.

有关在asp.net中管理角色的信息,请参阅以下文章:

如何:在ASP.NET 2.0中使用角色管理器 [
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[^]


这篇关于我如何创建角色会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆