ASP.NET:IsInRole 自己的实现

发布于 2024-12-27 08:21:56 字数 104 浏览 3 评论 0原文

是否可以覆盖asp.net中的逻辑IsInRole?我在数据库中使用自己的角色表,我想知道如何使用自己的逻辑。

就像从 PrincipialBase 继承一样。你知道一些方法吗?

Is it possible to override the logic IsInRole in asp.net? I use my own tables of roles in the database and I would like to know how to use own logic.

Something like inheriting from PrincipialBase. Do you know some ways?

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

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

发布评论

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

评论(3

自找没趣 2025-01-03 08:21:56

如果您正在使用 ASP.NET 身份验证和授权管理的其他方面,我只会使用 RoleProvider。但是,如果您有自己的数据库用于存储角色信息,并且已经有一个用于管理用户角色的 UI,则只需使用您的角色创建 GenericPrincipal 并在 PostAuthenticateRequest 期间用它替换 HttpContext.Current.User 即可(对于 ASP.NET) )。

MVC 略有不同,具体取决于您管理授权的方式。这是一个相关的问题。

asp.net mvc 中的应用程序角色管理(如何)?

最好每个请求加载一次用户的所有角色,然后在请求期间多次根据数据库检查角色。

I would only use RoleProvider if you are using other aspects of ASP.NET authentication and authorization management. However, if you have your own database for storing role information and already have a UI for managing user roles, you can get away with just creating a GenericPrincipal with your roles and replacing HttpContext.Current.User with it during PostAuthenticateRequest (for ASP.NET).

MVC is slightly different, depending on how you are managing authorization. Here is a related question.

application role management in asp.net mvc (How)?

It is better to load all the roles for a user once per request then to check roles against the database multiple times during the request.

小ぇ时光︴ 2025-01-03 08:21:56

然后,您需要实现自定义 RoleProvider。这是实现 RoleProvider 的指南

Then you need to implement a custom RoleProvider. Here is a guide to implement a RoleProvider.

深海夜未眠 2025-01-03 08:21:56

Microsoft 发布了默认提供程序的源代码(成员资格、角色等...)。
在实现您自己的提供程序时,这也是一个很好的参考。有一次我实现了自定义角色提供程序,它对我很有帮助。

Microsoft released the source code for the default providers (membership, role, etc...).
That is also a great reference when implementing your own provider. The one time I implemented a custom role provider, it served me very well.

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