以编程方式分配角色 [英] Assign role programatically

查看:62
本文介绍了以编程方式分配角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我想使用登录表单并创建用户向导,但工具箱中提供的登录控件使我感到困惑.所以我自己创建了表格,如下所示

ID用户名(PK)密码电子邮件序列问题回答角色
1 krishna windows @ krishna @ yahoo.com您的伴侣? Microsoft管理员
2 suresh billgates @ suresh@yahoo.com您的伴侣? Google员工

现在,我可以读取用户名和密码并将其分配给Forms Authentication
但是问题出在角色上,我想将角色分配给表单身份验证角色

我认为可能像下面的

字符串角色=(从数据库获得的值;
User.Identity.RoleName = role;

Hi i wanted to use login form and create user wizards but the login controls provided in toolbox makes me to confuse.so i created the table by my own like below

ID UserName(PK) Password Email SequerityQuestion Answer Role
1 krishna windows@ krishna@yahoo.com your partner ? Microsoft Admin
2 suresh billgates@ suresh@yahoo.com your partner ? Google Employee

now i can able to read the username and password and assign them to Forms Authentication
but the problem is with Role i wanted to assign Role to the Forms authentication role

i think it may like below

string role=(value obtained from database;
User.Identity.RoleName=role;

推荐答案

您好,我的一位朋友让我不高兴响应我仍然遇到错误
我尝试过如下

踪迹1:
Roles.AddUsersToRole(User.IdentityName,role);

足迹2:
Roles.AddUsersRole(TextBoxUserName.Text,role);

足迹3:
Roles.AddUsersToRole("suresh","Employee");

但我收到以下错误:
找不到该角色.

注意:
角色是
字符串角色=(从数据库获取的值);
Hi one of my friend given me fallowing Response i still getting error
i tried like below

trail 1:
Roles.AddUsersToRole(User.IdentityName,role);

trail 2:
Roles.AddUsersRole(TextBoxUserName.Text,role);

trail 3:
Roles.AddUsersToRole("suresh","Employee");

but i am getting the error below:
The Role was not found.

Note :
Here role is
string role=(value obtained from database);


这篇关于以编程方式分配角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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