Friday, October 17, 2008

Updating LastActivityDate in ASP.Net Membership Issue

So I've just finished rolling out the latest version of my application, which included a huge overhaul of the membership model. Essentially I replaced the entire Asp.Net Profile provider, with my own variation which fits better for my domain (Organization having many users).

I deploy out my site, and everything is running good for a couple of days, then we start to have issues (Which is a whole other story I will spare you all from). So before taking the site down I wanted to see who was using the site. I went over to my trusty administration interface and brought up the user report and what did I see?





UserLast Activity Last Login
JoeSmith10/17/08 11:00 AM10/17/08 11:00 AM
BobSmith10/17/08 11:05 AM10/17/08 11:05 AM


If you can't spot it the issue was all the users last activity date was the same as the last login. Now the kicker is that I have a client side timer invoking a web service every couple of minutes. This service makes a call to System.Web.Security.Membership.GetUser(). If you look up the msdn information you will see that GetUser() is supposed to update the LastActivityDate.

Digging around in the stored procedure [dbo].[aspnet_Membership_GetUserByName] you should see the following:

UPDATE dbo.aspnet_Users
SET LastActivityDate = @CurrentTimeUtc
WHERE @UserId=UserId



You can resolve this by modifying this to:

UPDATE dbo.aspnet_Users
SET LastActivityDate = @CurrentTimeUtc
WHERE LOWER(@UserName) = LoweredUserName


Before you purists jump down my back yes I left off ApplicationName because I only have one application, and our business currently mandates that all users in all of our applications share the same login and personalization. If you need to support multiple applications you can get the ApplicationId from the Application table. If you really need the sql drop me a comment and I will pull it out.

On a side note once the Connect site came back today I was able to confirm this is an old issue

No comments: