Monday, March 26, 2012

Membership GetAllUsers SP

Hello,

I am using the Membership application for my project. In the database (MS SQL 2005) the program created alot of SPs for the Membership, Roles, Profiles ...

Is there a function to return a list of users that are online? There is this functionaspnet_Membership_GetNumberOfUsersOnline andaspnet_Membership_GetAllUsers.

What i want is a Table with the usernames of all the users that are online in my application. No page index, just a big table with all the online users. I need to get all the usernames for another SP that i just build.

Any ideas?

To my knowledge there is not, but this would be a good one to add to the library. Realize that this would be a method that would be specific to the SQL or Custom Membership provider because AD would not be able to support this.

|||

I tried this, but i cant get it to return any rows, even tho atleast 4 people is logged in.

CREATEPROCEDURE [dbo].[aspnet_Membership_GetAllOnlineUsers]
@.ApplicationNamenvarchar(256),
@.MinutesSinceLastInActiveint,
@.CurrentTimeUtcdatetime
AS
BEGIN
DECLARE @.DateActivedatetime
SELECT @.DateActive=DATEADD(minute,-(@.MinutesSinceLastInActive), @.CurrentTimeUtc)

CREATETABLE #PageIndexForUsersNames
(
Usernamenvarchar(20)NOTNULL
)

INSERTINTO #PageIndexForUsersNames(Username)
SELECT u.Username
FROM dbo.aspnet_Users u(NOLOCK),
dbo.aspnet_Applications a(NOLOCK),
dbo.aspnet_Membership m(NOLOCK)
WHERE u.ApplicationId= a.ApplicationIdAND
LastActivityDate> @.DateActiveAND
a.LoweredApplicationName=LOWER(@.ApplicationName)AND
u.UserId= m.UserId
SELECT UsernameFROM #PageIndexForUsersNames
END

And then i tried to run the following:

EXEC aspnet_Membership_GetAllOnlineUsers
@.ApplicationName= N'//',
@.MinutesSinceLastInActive= 10,
@.CurrentTimeUtc='2007-11-15 18:45'

The applicationname did i take from the applications table.

Any ideas?

|||

Sorry that was the old, this is what i am trying:

aspnet_Membership_GetAllOnlineUsers
@.ApplicationNamenvarchar(256),
@.MinutesSinceLastInActiveint,
@.CurrentTimeUtcdatetime
AS
BEGIN
DECLARE @.DateActivedatetime
SELECT @.DateActive=DATEADD(minute,-(@.MinutesSinceLastInActive), @.CurrentTimeUtc)

SELECT u.Username
FROM dbo.aspnet_Users u(NOLOCK),
dbo.aspnet_Applications a(NOLOCK),
dbo.aspnet_Membership m(NOLOCK)
WHERE u.ApplicationId= a.ApplicationIdAND
LastActivityDate> @.DateActiveAND
a.LoweredApplicationName=LOWER(@.ApplicationName)AND
u.UserId= m.UserId
END

|||

You've specified a UTC time that is still in the future.

@.CurrentTimeUtc='2007-11-15 18:45' won't be for another 30 minutes.

|||

To be honest, I'm still not sure why the ASP.NET team decided to do it that way, it seems against best practices to have the client application trying to send in times when the window we're looking for is normally minutes, especially when it's extremely easy to make sure that we always use a single clock for reference:

aspnet_Membership_GetAllOnlineUsers
@.ApplicationNamenvarchar(256),
@.MinutesSinceLastInActiveint

AS
BEGIN
DECLARE @.DateActivedatetime
SELECT @.DateActive=DATEADD(minute,-(@.MinutesSinceLastInActive), GetUtcDate())

SELECT u.Username
FROM dbo.aspnet_Users u(NOLOCK),
dbo.aspnet_Applications a(NOLOCK),
dbo.aspnet_Membership m(NOLOCK)
WHERE u.ApplicationId= a.ApplicationIdAND
LastActivityDate> @.DateActiveAND
a.LoweredApplicationName=LOWER(@.ApplicationName)AND
u.UserId= m.UserId
END

No comments:

Post a Comment