商店/指定认证的用户角色 [英] Store/assign roles of authenticated users

查看:85
本文介绍了商店/指定认证的用户角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级站点使用MVC和我期待的设置身份验证的最佳方式。

I am upgrading a site to use MVC and I am looking for the best way to set up Authentication.

在这一点上,我有登录过工作的Active Directory:验证用户名和密码,然后设置验证cookie的

At this point, I have the log-in working off of Active Directory: validating a username and password, and then setting the Auth cookie.

如何存放在登录时用户的角色信息,为了让我的控制器看到这些角色为用户浏览网站?

How do I store the user's role information at time of log-in, in order for my controllers to see those roles as the user navigates through the site?

[Authorize(Roles = "admin")]

我没有问题,得到从Active Directory的角色列表。我只是不知道往哪里放他们,使控制器会看到他们。

I have no problem getting a list of roles from Active Directory. I just don't know where to put them so that the controllers will see them.

推荐答案

在验证您的用户,您生成一个新的GenericPrincipal实例。构造函数的字符串这对于用户的角色数组。现在设置HttpContext.Current.User等于通用的本金和写AUTH的cookie,而且应该这样做。

When you authenticate your user, you generate a new GenericPrincipal instance. The constructor takes an array of strings which are the roles for the user. Now set HttpContext.Current.User equal to the generic principal and write the auth cookie, and that should do it.

这篇关于商店/指定认证的用户角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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