简体   繁体   English

ASP.NET 2.0安全成员资格提供程序模式

[英]ASP.NET 2.0 Security Membership Provider Pattern

I am creating a website in ASP MVC. 我正在ASP MVC中创建一个网站。 Can anyone give me some advice on using the built-in membership provider in the following way. 任何人都可以通过以下方式给我一些使用内置成员资格提供程序的建议。

I want my users to create an Administrative account for themselves and then create accounts for the people in their organization, or the people that they want to give access to. 我希望我的用户为自己创建一个管理帐户,然后为其组织中的人员或他们要授予访问权限的人员创建帐户。

I guess in a Database it will look something like this: 我猜在数据库中它将看起来像这样:

Companies have Administrators. 公司有管理员。 Administrators can give users access. 管理员可以授予用户访问权限。

I am sure this pattern is used all over the place, I am just not sure how to implement it. 我确定这个模式在各处都被使用了,我只是不确定如何实现它。 Especially using the membership providers. 特别是使用成员资格提供程序。

Thanks, 谢谢,

David 大卫

There is nothing special in implementing this. 实现这一点没有什么特别的。 It can be easily accomplished by built-in features of ASP.NET 2.0: 可以通过ASP.NET 2.0的内置功能轻松实现:

  1. Configure Web site to use membership (via web.config ) 配置网站以使用成员身份(通过web.config
  2. Enable role management (via web.config <roles enabled="true"> tag ) 启用角色管理(通过web.config <roles enabled="true"> tag
  3. Add administrator accounts to Administrators role. 将管理员帐户添加到Administrators角色。
  4. Control access to the administrative pages by using [Authorize(Roles="Administrators")] attribute in the controller action. 通过使用控制器操作中的[Authorize(Roles="Administrators")]属性来控制对管理页面的访问。
  5. Require authentication on other non-admin actions ( [Authorize] ) 要求对其他非管理员操作进行身份验证( [Authorize]

When I did this, I used the Membership Provider for authentication however, the organization concept I created externally from the Provider. 当我这样做时,我使用成员资格提供程序进行身份验证,但是,我是从该提供程序外部创建的组织概念。 You could use the Profile Provider. 您可以使用配置文件提供程序。

As for roles I would still use the Roles within the ASP.Net Membership Model. 至于角色,我仍将使用ASP.Net成员资格模型中的角色。

You can create a role for those people and name it something like organizational-admin, though that's a bit long, you catch my drift :). 您可以为这些人创建一个角色,并命名为“ organic-admin”之类的名称,尽管这有点长,但您会觉得很不舒服:)。 And give those the power to create users with a regular user role. 并赋予他们创建具有常规用户角色的用户的权力。 At least that's how i did it in one of my applications. 至少那是我在其中一个应用程序中做到的方式。

Ofcourse you'll keep the admin to yourself or to the person who is in charge of this particular site. 当然,您将让管理员自己或由负责此特定网站的人员来管理。

Gu's blog has a small example of how to implement the roles in an action filter. Gu的博客提供了一个有关如何在动作过滤器中实现角色的小例子。

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

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