我可以利用user.IsInRole,而无需使用会员? [英] can I make use of user.IsInRole without using Membership?

查看:263
本文介绍了我可以利用user.IsInRole,而无需使用会员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用窗体身份验证,我想利用角色,可我不知怎么设置用户的角色,而不会员?

I'm using Forms authentication and I would like to make use of roles, can I somehow set the role of the user without Membership ?

推荐答案

一个简单的方法来做到这一点是角色列表存储在身份验证票据,当用户进行身份验证。那么对于每一个请求( Application_AuthenticateRequest Global.asax文件的方法),你提取的角色,将它们添加到的GenericPrincipal 对象,并设置 HttpContext.User中属性。

A simple way to do it is to store the list of roles in the authentication ticket when the user is authenticated. Then for every request (Application_AuthenticateRequest method of the global.asax file) you extract the roles, add them to a GenericPrincipal object and set the Httpcontext.User property.

User.IsInRole(角色) [AuthorizeAttribute(角色=角色)] 将然后恢复正常。

请参阅this回答为code详细介绍了如何做到这一点。

See this answer for code detailing how to do it.

这篇关于我可以利用user.IsInRole,而无需使用会员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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