重写 SQLMembershipProvider
.net 框架中是否有内置方法来执行以下操作:
- 从用户名/用户 GUID 获取角色 GUID
- 从角色 GUID 获取角色名称
到目前为止,我一直在向 asp_roles 和 asp_users 表发送查询以获取该信息,我想知道是否有更好的方法来做到这一点?
我将以下方法存储在 ASPUtilities 类中:
getRoleGUID(guid userGuid) { LINQ joins }
getRoleGuid(string userName) { LINQ joins }
getRoleName(guid roleGuid) { LINQ joins }
编辑:
我刚刚研究了扩展 SQLMembershipProvider 示例。
很少有示例完全重写 SQLMembershipProvider,但我认为我感兴趣的只是添加一些额外的方法来使用 LINQ 处理角色。这可行吗?
Is there built in methods into .net framework to do the following:
- Get role GUID from user name/user GUID
- Get role name from role GUID
So far I have been sending queries to the asp_roles and asp_users tables to obtain that information and I'm wondering if there is a nicer way of doing this?
I have the following methods that I store in the ASPUtilities class:
getRoleGUID(guid userGuid) { LINQ joins }
getRoleGuid(string userName) { LINQ joins }
getRoleName(guid roleGuid) { LINQ joins }
EDIT:
I have just looked into extending SQLMembershipProvider examples.
Few examples completely override the SQLMembershipProvider, but I think what I'm interested is just adding few extra methods to deal with the roles by using LINQ. Is this feasible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您扩展 SQLMembership 提供程序,它将执行完全相同的操作,将查询发送到数据库以获取该信息,因为 roleID 不存储在会话中。如果您不想经历那么多麻烦,您可以做一些事情。
If you extend the SQLMembership provider, it will do the exact same thing, send queries to the database to get that information since the roleID is not stored in session. If you don't want to go through that much trouble, you could do a few things.