Membership.GetUser() does not update the last-activity date/time stamp for the user

I am writing the "Who is online" function for my application and found that Membership.GetUser() does not update the last-activity date/time stamp for the user as expected. This make my application considers a user offline after he/she logs into the system after the number of minutes specified in the "userIsOnlineTimeWindow" property (even he/she is still working in the application). I have searched on web all day and found no clues on this problem.

Has anyone encountered the same kind of problem? Any help would be greatly appreciated.

Thanks a lot. 

0
henry_asp_net
10/22/2007 1:15:08 PM
asp.net.security 27051 articles. 1 followers. Follow

4 Replies
1164 Views

Similar Articles

[PageSpeed] 49

Membership.GetUser() calls Membership.GetUser(userName, true), which calls Provider.GetUser(userName, true); If this isn't updating your last activity time, then there's a problem with your membership provider.

However, if you call Membership.GetUser(userName) or Membership.GetUser(providerUserKey), the userIsOnline flag defaults to false, so your last activity time won't be updated. In this case, you should replace your calls with Membership.GetUser(userName, true) or Membership.GetUser(providerUserKey, true) in order to update the activity time.

0
RichardD
10/22/2007 5:56:00 PM

RichardD, thanks for your reply. Actually, I am using the built-in SqlMembershipProvider except that I reconfigure it in the web.config file to relax the password requirement. Below is the configuration that I have made in web.config:

<membership defaultProvider="AspNetSqlMembershipProviderPasswordRelaxed" userIsOnlineTimeWindow="15">
      <providers>
        <add name="AspNetSqlMembershipProviderPasswordRelaxed" type="System.Web.Security.SqlMembershipProvider" connectionStringName="AppConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression="" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0"/>
      </providers>
</membership>

I would be grateful if you could provide any further assistance. Thanks a lot.

0
henry_asp_net
10/23/2007 12:52:06 AM

Finally, I found the cause of the problem. It is because Membership.GetUser() won't update the last activity timestamp of the user in the data store. It will only update the last activity timestamp in the MembershipUser object that is returned. So, in order to update the last activity timestamp of the user in the data store, we have to call Membership.UpdateUser(user) by ourselves. I found this solution on http://www.sitepoint.com/forums/showthread.php?t=380584.

0
henry_asp_net
10/23/2007 1:19:49 AM

If you look at the two GetUser methods on the SqlMembershipProvider class, they call either "dbo.aspnet_Membership_GetUserByName" or "dbo.aspnet_Membership_GetUserByUserId", passing the userIsOnline flag to the @UpdateLastActivity parameter. However, there seems to be a bug in the "dbo.aspnet_Membership_GetUserByName" procedure, in that it attempts to update the user by ID without ever reading the ID.

To fix the problem, you can execute the following in your membership database: 

IF (EXISTS (SELECT name
FROM
sysobjects WHERE (name = N'aspnet_Membership_GetUserByName')
AND (type = 'P')))
DROP PROCEDURE dbo.aspnet_Membership_GetUserByName
GO
CREATE PROCEDURE dbo.aspnet_Membership_GetUserByName
@ApplicationName nvarchar(256),
@UserName nvarchar(256),
@CurrentTimeUtc datetime,
@UpdateLastActivity bit = 0
AS
BEGIN
DECLARE
@UserId uniqueidentifier

SELECT TOP
1 @UserId = u.UserId
FROM dbo.aspnet_Applications a, dbo.aspnet_Users u, dbo.aspnet_Membership m
WHERE LOWER(@ApplicationName) = a.LoweredApplicationName AND u.ApplicationId = a.ApplicationId AND LOWER(@UserName) = u.LoweredUserName AND u.UserId = m.UserId If (@@ROWCOUNT = 0) -- Username not found RETURN -1

IF (@UpdateLastActivity = 1)
BEGIN
UPDATE
dbo.aspnet_Users
SET LastActivityDate = @CurrentTimeUtc
WHERE @UserId = UserId
END

SELECT
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_Users u, dbo.aspnet_Membership m
WHERE @UserId = u.UserId AND u.UserId = m.UserId

IF ( @@ROWCOUNT = 0 ) -- User ID not found RETURN -1

RETURN 0
END GO GRANT EXECUTE ON dbo.aspnet_Membership_GetUserByName TO aspnet_Membership_BasicAccess
GRANT EXECUTE ON dbo.aspnet_Membership_GetUserByName TO aspnet_Membership_ReportingAccess
GO
 

NB: I've kept this as close as possible to the style of the original. It could be improved by using inner joins instead of the old-style joins, but this could break in the unlikely event that you're using an older version of SQL Server.

I have reported this as a bug: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=306297 

0
RichardD
10/23/2007 11:11:55 AM
Reply:

Similar Artilces:

Seperate Date and Time Merge; done at SQL Update or C# .NET then Update
I do realize that his could be posted in a few spots but I think the answer is in the SQL. I have a ASP.NET page, with a SqlDataSource, Text Box and Calendar Controls. I have the textbox and calendar controls eval'ed to the same sql data source DateTime Field. The text box is formatted eval to small time and the calendars eval has no formatting. ex: <asp:TextBox ID="START_TIME" Text='<%# Eval("EVENT_START","{0:t}") %>' runat=server Width=200></asp:TextBox> I want to merge the two controls; one has the date the other has the time when I update the pages data to the SqlDa...

Membership Last Activity Date Problem
I am trying to use Membership, Roles and Profiles using an Access Database instead of SQLserver. I have set things up following tutorials by Spaanjaars ( http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=404 ) and Scott Mitchell ( http://aspnet.4guysfromrolla.com/articles/010307-1.aspx ).  Most everything I've tried seems to work, except that whenever a user logs on the LastActivityDate is updated for ALL users.  This of course messes up various features like getting number of users online.  Any advice on getting this fixed would be welcome.   what...

How to find out the date/time of when a record was last update?
Hi, Is there a way to determine the date or/time of when a record was last update, w/out using audit ? thanks in advance, Karena Add a timestamp or datetime column to you table to track this. steve [TeamSybase] but is there any way to track it down if i didn't have the timestamp column set up? thanks, Karena Not easily, and probably not at all. For instance, if you have a series of database dumps, you could start loading them and checking the contents of the row until you find the db dumps where it has value (a) in the first dump and (b) in the next dump -...

updating active directory user profiles with.net
hi all; i'am using this forum first time. i like this very much. i have a questions abut active directory with .net. so i wanna updating user profiles using asp.net. for example there is a computer laboratuar , a windows 2003 server and a web page that using active directory accounts to authenticate system. for example me. i wanna updating my profile using web page , if i authenticated system. i hope, i can tell my questions:) 'cause my english not good. thanks.Mesut KOSUCUSoftware Engineer...

Membership Last Activity Date Problem #2
I was looking at my membership table and was noticing that some of the last activity dates where in the future.  Why is this happening?  The server time is set to eastern standard which is the time zone I am in.  Any ideas? Are they 4 hours ahead?  If so I bet it's setting the time to UTC time which I think is a good idea.Rob Millswww.dotnetadvisor.com Hi try this example: suppose you have Login.aspx and Default.aspx which Login user go to it after Login In Login.aspx.cs protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)  &nb...

Retrive updated users from Active Directory by chaged date?
Hi all! I'm trying to retrive users from ActiveDirectory, that has been updated after a given date, using a DirectoryServices.DirectorySearcher (in c#) . The problem is I don't get the filter to work, I've tried the following: DirectorySearcher Searcher = new DirectorySearcher(RootDSE); Searcher.Filter = "(When-Changed>1901-11-12 00:00:00)"; or Searcher.Filter = "(When-Changed>1901-01-01)"; or Searcher.Filter = "(whenChanged>1601-11-12 00:00:00)"; And a few others, but all I get is a ".search filter is invalid"...

How to find out the date/time of when a record was last update? #2
...

Incorrect date/time stamps on v3.6 Updates
Name: Robert Email: scenicdotrouteatsbcglobaldotnet Product: Firefox Summary: Incorrect date/time stamps on v3.6 Updates Comments: When I click on Show Updates, the last two that downloaded for version 3.6 were 3.6.2 & 3.6.3, and BOTH show "pre-PC" dates like this: "Installed on December 31, 1969 18:00:00" instead of the actual dates in the present. I don't know if you can fix it, and that might not even matter to you, but even though you say not to expect a response, I've still included my e-mail in case you have a question for me. Browser...

How to Know the last access date and Time for Sybase Users
Auditor want to know when the users accessed the sybase server last time. We don't have any login auditing enable. Require experts help ... Easiest method ... > Auditor want to know when the users accessed the sybase > server last time. We don't have any login auditing enable. 1 - enable auditing of logins (don't forget the assorted overhead of managing space usage in the sybsecurity database) 2 - write a login trigger (stored proc) to dump 'login' info to a home grown auditing table > Require experts help ... Oh, in that case ... show t...

Update Only the Time in a date time field
Hi,i have a table having a datatime field and on a datagrid I need only to display and update the time part. I'm using select CONVERT(CHAR(8), JobStartTime, 8) AS StartTime from table to get the date. What is  the best way to write the update command . What woul dbe the best approch.   Regards, Vijay  1. Instate of doing formatting in the SQL, Try to do that is the DataGrid with FormatString. 2. To Update the Database , you can do that in two ways.    a. Either go for Store Procudure. Send the TIME you want to set for record. Your SP should some ...

date/time or date and time
I am setting up an SQL database and I will need to get differences in dates. For example I have a start date, start time, completion date and completion time and I want to get the difference between the start and completion. Would it be better to have one field with both date and time in it, or better to have a date field and a time field? Even though I have already started setting up the tables with seperate fields for date and time I am now leaning toward one field with date/time in it. (Only because that is the way I had to do it when setting up an Excel spreadsheet for a similar ta...

How do you know the last date/time update stats is run on a table?
regards, Abel The nitty-gritty is in sysstatistics. An SP that generates the output below is my sp_newstats proc in the dba.sql file at http://www.bossconsulting.com/sybase_dba/ However you better read the Installation Guide first since other procs also have to be loaded. A quicker way would be to use the code and strip off the execution of sp_date, etc. that prettyprints the dates. sp_newstats CURRENT DATE/TIME -------------------------------- May 6, 2001 (08:40:53 AM) THERE ARE 48 STATISTICS ROWS FOR 9 SYSTEM TABLES IN systatistics. THERE ARE 4...

Updated Date/Time all Time Zones
Hi,I am working on a Web ASP.NET APPLICATION, which has different sub domains for all the different Countries, I need to show the Current Date/Time based on DayLight Saving as well but I am unable to find a perfect solution for this, I am not looking for a Paid WebService as the Site might not show the Date/Time if the Vendor stops that WebService,it is one crucial requirement and I am sure there should be a way in asp.net 2.0 to figure this out.......thanks    A fundamental rule in technology says whatever can be done will be done See this: http://www.timeanddate.com/time/dst200...

Convert the times stamp value from DB to a valid user readable date
Dear allI have a data list where i am presenting the values that i get from a database. One of the fields has to represent the creating date of the record that is timestamp value in the DB. When i try to present it in a label i get System.Byte [] . Is there any way to convert this to a user readable format and put it inside the data list? Cheers Dan Hi,Dan_dan :What is the data type of the field in db you want to bind ? Is it  datatime?Would you plz post some relative code here? Best Regards,__________________________________________________Sincerely,Rex LinMicrosoft On...

Web resources about - Membership.GetUser() does not update the last-activity date/time stamp for the user - asp.net.security

Shark Week Owned 35% of Cable Social-TV Activity Last Week - Social TV and Trending Topics: What's Hot ...
You’ve read all of your free items this month. To register, get added benefits and unlimited access to articles, Become a Member . Already a ...

Google: We drove $80B in U.S. economic activity last year
The company says that it was able to tally that mark for 1.8 million businesses, Web site publishers, and non-profits across the U.S.

Google: We drove $80 billion of U.S. economic activity last year
The company says that it was able to tally that mark for 1.8 million businesses, Web site publishers, and non-profits across the U.S.

Resources last updated: 1/21/2016 9:48:00 PM