【发布时间】:2013-06-05 18:38:20
【问题描述】:
我正在尝试使用 FormsAuthentication,目前使用用户名和密码可以正常工作。我需要将用户角色添加到表单身份验证票证中,并且我没有使用 ASP.NET 成员资格。
if (rep.CheckUser(model.UserName, model.Password,out UserRole))//Check User
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
// Roles.AddUserToRole(model.UserName, UserRole);//This Requires Membership
return Redirect(FormsAuthentication.DefaultUrl);
}
【问题讨论】:
-
您现在使用哪种机制来处理角色?
-
@HuseinRoncevic 在我的数据库表中,我有一个用户的用户名、密码和角色。我想将从数据库表中检索到的角色传递给身份验证票
-
不确定它是否有效。您只需将用户名放在 auth cookie 中,然后对于每个传入请求,您从 auth cookie 中读取用户名并从数据库加载其他详细信息。这可以在
ActionFilter中完成。
标签: asp.net asp.net-mvc login asp.net-membership forms-authentication