ASP.NET:IsInRole 自己的实现
是否可以覆盖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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您正在使用 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.
然后,您需要实现自定义 RoleProvider。这是实现 RoleProvider 的指南。
Then you need to implement a custom RoleProvider. Here is a guide to implement a RoleProvider.
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.