简体   繁体   English

Asp.net成员资格和身份验证

[英]Asp.net Membership & Authentication

I'm beginning to design the infrastructure of web application developed with ASP.NET MVC preview 2 as a learning experience. 我开始设计使用ASP.NET MVC Preview 2开发的Web应用程序的基础结构,作为学习的经验。 I have my own domain model and database schema I wish to use for authentication. 我有自己的域模型和数据库架构,希望用于身份验证。

I want to perform a variant of role base authentication. 我想执行基于角色的身份验证的变体。 However, I can't seem to wrap my head around how to do this. 但是,我似乎无法全神贯注于如何执行此操作。

I have a user that has access to a "Blog". 我有一个有权访问“博客”的用户。 How can I perform authorization where the user is in the expected role, but where the user belongs to the aforementioned "Blog" 在用户具有预期角色但用户属于上述“博客”的地方,如何执行授权

Would a custom role provider be needed, or can should I perform the logic in a authorization attribute for the controller actions; 是需要自定义角色提供程序,还是可以在控制器操作的授权属性中执行逻辑? querying the authenticated user's BlogId and performing the authorization logic there. 查询经过身份验证的用户的BlogId,并在那里执行授权逻辑。 I'm unaware of any built in way to currently do this, but if there is please correct me. 我不知道目前有任何内置方法可以执行此操作,但是如果有请纠正我。

If possible, an example of a custom role provider, or authorize attribute that would provide this functionality would be great. 如果可能的话,提供此功能的自定义角色提供程序或authorize属性的示例将非常有用。

Thank you 谢谢

It sounds like what you are wanting is the ability to have both a role and an ownership check. 听起来您想要的是既具有角色又具有所有权检查的能力。 For example, a user may have the role of "author" but would also need to have an ownership relationship with a particular blog to actually be able to create or update blog entries. 例如,用户可能具有“作者”的角色,但还需要与特定博客具有所有权关系,才能实际创建或更新博客条目。 Using a standard role provider along with a custom authorization attribute that knows how to check for ownership -- essentially a particular foreign key relationship between the entity for the action and the current user entry in the DB -- seems to be a reasonable way to approach this. 使用标准角色提供程序以及知道如何检查所有权的自定义授权属性-本质上是用于操作的实体与数据库中当前用户条目之间的特定外键关系-似乎是一种合理的处理方法这个。

You can find some sample code on my answer to this similar question . 您可以在类似问题的 答案中找到一些示例代码。

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

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