重写 SQLMembershipProvider

发布于 2024-09-02 19:14:32 字数 519 浏览 2 评论 0原文

.net 框架中是否有内置方法来执行以下操作:

  1. 从用户名/用户 GUID 获取角色 GUID
  2. 从角色 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:

  1. Get role GUID from user name/user GUID
  2. 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 技术交流群。

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

发布评论

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

评论(1

生生不灭 2024-09-09 19:14:32

如果您扩展 SQLMembership 提供程序,它将执行完全相同的操作,将查询发送到数据库以获取该信息,因为 roleID 不存储在会话中。如果您不想经历那么多麻烦,您可以做一些事情。

  1. 使用您可以调用的这些方法创建一个自定义类,并将返回您的角色的 ID。本质上,将所有查询移至一个位置。
  2. 登录时将角色 ID 存储在会话中。调用上面创建的方法一次,不要每次都重新查询。然而,这并不是 100% 的安全风险,因为您在会话中存储一些可能敏感的角色信息(id)。可能只是过于谨慎:)

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.

  1. Create a custom class with these methods that you can call and will return the ID for you of your role. Essentially, move all of your queries to one location.
  2. Store the role ID in session on login. Call your method you created above once and don't requery everytime. Not 100% of the security risks with this one, however, since you are storing some possibly sensitive role information, the id, in session. Might just be overly cautious though :)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文