Asp.net 会员资格和验证

发布于 2024-08-08 22:53:38 字数 340 浏览 2 评论 0原文

我开始设计使用 ASP.NET MVC 预览版 2 开发的 Web 应用程序的基础结构作为学习体验。 我有自己的域模型和数据库架构,希望用于身份验证。

我想执行角色基础身份验证的变体。然而,我似乎不知道如何做到这一点。

我有一个可以访问“博客”的用户。我如何在用户处于预期角色但属于上述“博客”的情况下执行授权

是否需要自定义角色提供程序,或者我应该在控制器操作的授权属性中执行逻辑;查询经过身份验证的用户的 BlogId 并在那里执行授权逻辑。我不知道目前有任何内置方法可以执行此操作,但如果有,请纠正我。

如果可能的话,提供此功能的自定义角色提供程序或授权属性的示例将非常好。

谢谢

I'm beginning to design the infrastructure of web application developed with ASP.NET MVC preview 2 as a learning experience.
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. 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.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合约呢 2024-08-15 22:53:38

听起来您想要的是同时拥有角色和所有权检查的能力。例如,用户可能具有“作者”的角色,但还需要与特定博客具有所有权关系才能真正能够创建或更新博客条目。使用标准角色提供程序以及知道如何检查所有权的自定义授权属性(本质上是操作实体与数据库中当前用户条目之间的特定外键关系)似乎是一种合理的方法这。

您可以在 我对此的回答类似问题

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文