寻找 MemberShip.GetAllUsers(startDate,endDate) 功能

发布于 2024-08-02 06:56:27 字数 527 浏览 4 评论 0原文

我正在利用 .Net Membership 类创建一个用户批准界面。我有一个执行 Membership.GetAllUsers() 的页面,并将结果发送到数据网格。我通过 MembershipUser.IsApproved 过滤它们。

我的问题是由于我在 GetAllUsers() 时遇到的缓慢。

由于我不需要拉下所有用户,而是拉下所有 CreateDate 落在特定范围内的用户,我想知道是否有一种方法可以根据日期范围获取子集?

希望为有类似情况的人更新:


更新: 所以,我最终实际上没有使用下面的答案。尽管它确实正确地解决了具体问题。不管怎样,我真正的问题是,获取用户的子集(即那些需要“批准”的用户 - 因为我的管理员控制着这个(而不是用户))。我的解决方案是将新注册的用户分配给“awaitingapproval”角色,然后我能够获取 Roles.UsersInRole(“awaitingapproval”),向管理员显示这些角色,并具有“批准”用户的能力。然后,每个批准的用户将从“等待批准”中删除并分配给新角色。

I'm creating a user approval interface leveraging the .Net Membership class. I have a page that does a Membership.GetAllUsers(), and I spit the results to a datagrid. I filter them by MembershipUser.IsApproved.

My Issue is due to slowness I'm hitting while I GetAllUsers().

Since I don't need to pull down all of the users, but rather, say, all of the users with a CreateDate falling within a certain range, I'm wondering if there's a way to grab a subset based on date-range?

Wanted to Update for those in a similar situation:


UPDATE:
So, I ended up actually not using the answer below.. Although, it does address the specific question properly. Anyhow, my real problem was, grabbing a subset of Users (i.e. those requiring "approval" - Since my Admin holds control of this (not the users)). My solution was to assign newly signedup users to an "awaitingapproval" role, then I was able to grab Roles.UsersInRole("awaitingapproval"), display those to the Admin with the ability to "approve" a user. Each approved user is then dropped from "awaitingapproval" and assigned to a new role.

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

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

发布评论

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

评论(2

陈独秀 2024-08-09 06:56:27

尽管 GetAllUsers() 有重载来根据索引返回用户子集(即一次用户“页面”),但您无法使用任何东西来将其基于这样的自定义逻辑。

我可能会编写一个继承基本成员资格提供程序的新类,并为 GetAllUsers() 添加新的重载。

您可以使用 Reflector 查看 System.Web.Security.SqlMembershipProvider 的源代码以 GetAllUsers() 的实现为起点。

Although there are overloads for GetAllUsers() to return a subset of users based on index (i.e. one "page" of users at a time), there is nothing that you could use to base it on custom logic like this.

I would probably write a new class that inherits the base membership provider and add a new overload for GetAllUsers().

You can use Reflector to see the source code for System.Web.Security.SqlMembershipProvider's implementation of GetAllUsers() as a starting point.

错々过的事 2024-08-09 06:56:27

我宁愿说你可以使用 Linq 来查询值,但当我尝试它时,我得到了一个错误。

users.AsQueryable()
-->Exception : source is not source is not IEnumerable

您可以编写一个存储过程来代替使用它,该存储过程根据给定的创建日期从数据库获取所有用户,并从该结果开始。

--> SQL数据库中会自动创建Membership,只需根据给定的参数修改aspnet_Membership_GetAllUsers存储过程

SELECT u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
        m.CreateDate,
        m.LastLoginDate,
        u.LastActivityDate,
        m.LastPasswordChangedDate,
        u.UserId, m.IsLockedOut,
        m.LastLockoutDate
FROM   dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p
WHERE  u.UserId = p.UserId AND u.UserId = m.UserId AND
       p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound AND
       m.CreateDate BETWEEN @pFirstDate AND @pSecondDate //Additional

ORDER BY u.UserName

I would rather say that you could use Linq for querying values , but as I tried it I get an error.

users.AsQueryable()
-->Exception : source is not source is not IEnumerable

Instead of using this you can write a stored procedure which gets all users from database by your given creating date and go over from that result.

--> There is on which Membership automatically creates in SQL Database, just Modify aspnet_Membership_GetAllUsers Stored Procedure by your given parameters

SELECT u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
        m.CreateDate,
        m.LastLoginDate,
        u.LastActivityDate,
        m.LastPasswordChangedDate,
        u.UserId, m.IsLockedOut,
        m.LastLockoutDate
FROM   dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p
WHERE  u.UserId = p.UserId AND u.UserId = m.UserId AND
       p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound AND
       m.CreateDate BETWEEN @pFirstDate AND @pSecondDate //Additional

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