简体   繁体   English

asp.net使用成员资格提供程序设置角色

[英]asp.net use membership provider to set role

I am building my first asp.net app from scratch. 我正在从头开始构建我的第一个asp.net应用程序。 I have two different membership providers. 我有两个不同的会员资格提供者。 One is a basic sql provider while the other is active directory. 一个是基本的sql提供程序,而另一个是活动目录。 The user "role" is determined by how the user logs in. I want to use the Role Manager functionality of asp.net but I don't want to build the whole role provider part when I really don't have "roles" in my application, I have two membership types. 用户“角色”由用户登录方式决定。我想使用asp.net的角色管理器功能,但是当我确实没有“角色”时,我不想构建整个角色提供程序部分在我的应用程序中,我有两种成员资格类型。

Is there a way to set the role of the user through the membership provider at login or in some way mark a logged in user as having been authenticated by sql or AD? 有没有办法在登录时通过成员资格提供程序设置用户的角色,或者以某种方式将登录的用户标记为已通过sql或AD进行身份验证?

This is my first asp.net app, am I even thinking about this the right way? 这是我的第一个asp.net应用程序,我是否还在考虑正确的方法?

Roles and membership are two distinct things in asp.net. 角色和成员资格是asp.net中的两个不同之处。

On login you need to assign a flag to the user object which identifies how they logged in. 登录时,您需要为用户对象分配一个标志,以标识他们的登录方式。

Then in 然后在

public override string[] GetRolesForUser(string username)

check that flag and return an appropriate role 检查该标志并返回适当的角色

You are trying to use the roles in a manner they aren't designed for, and I'm afraid you'll have to have a role-provider for it to work. 您正在尝试以并非为角色设计的方式使用这些角色,而且恐怕您必须要有一个角色提供程序才能正常工作。

Why not use the MembershipUser.ProviderName property to check what provider provided the users identity? 为什么不使用MembershipUser.ProviderName属性检查哪个提供程序提供了用户身份?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM