12

In asp.net (using MVC, but this happens in regular too)

Profile.GetProfile(username);

will update the LastActivityDate for that user. This is not intended when someone else is viewing that user's profile.

In the membership class you can specify whether to update this date with a second param, like so:

Membership.GetUser(username, false); // doesn't update LastActivityDate
Membership.GetUser(username, true); // updates LastActivityDate

Is there anyway to do something similar in the Profile provider without writing my own provider?

Daniel Dyson
  • 13,192
  • 6
  • 42
  • 73
WildJoe
  • 5,740
  • 3
  • 26
  • 30

2 Answers2

10

You might use one ugly workaround which includes changing aspnet_Profile_GetProperties stored procedure. This one is responsible for getting the properties while accessing user profile.

Open this procedure and you will find following code at the bottom:

IF (@@ROWCOUNT > 0)
BEGIN
    UPDATE dbo.aspnet_Users
    SET    LastActivityDate=@CurrentTimeUtc
    WHERE  UserId = @UserId
END

Remove it in order to stop updating the LastActivityDate. You will still get LastActivityDate updated when calling Membership.GetUser(username, true);.

Radek Stromský
  • 838
  • 3
  • 12
  • 27
  • 3
    Yeah, editing the sproc is what I ended up doing. At some point I'll probably re-write the profile portion of my site to something custom or use a third party, but I needed a quick fix. – WildJoe Aug 30 '11 at 17:40
1

You might look at using a provider that someone else has written, rather than write your own.

This one on Scott Guthrie's blog includes stored procedures which could be called directly by your own code to get the information:

http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx

This page has an msi download which installs a sample application for working with custom Profile data. The table based profile performs a lot better than the default on, where all of the profile data is contained in a single database field. The table based one is also a lot easier to query directly, which will help you with your question. The stored procedure from the sample schema is called getCustomProfileData

Otherwise, just query the database directly.

Daniel Dyson
  • 13,192
  • 6
  • 42
  • 73
  • 1
    I strongly advise against querying the database directly. Otherwise, great post. – bzlm Aug 09 '10 at 11:38
  • @bzlm I respect your string views and I can't disagree if you don't give me a reason. :) I've been querying databases for more years than I like to remember and havent had too many difficulties. – Daniel Dyson Aug 09 '10 at 12:12