Wednesday, September 10, 2008

Membership Profile read updates LastUpdatedDate

This is in reference to custom membership provider we built for Oracle but the concept is similar to SQL Membership. Found that the profile table has both LastActivityDate and LastUpdatedDate getting updated. A little digging into it took me to the root cause of the problem - usage of Profile to read custom Profile properties (XML).


For example, any place we use Profile.LastName to get the last name then it's updating the LastActivityDate (as expected) and also updates LastUpdatedDate. Which is not intended. The idea is to update the latter column only when the user modifies and saves their profile.


If we need to use Profile.Get in any situation without updating the LastUpdatedDate then one of our choice is to use ProfileCommon. Here’s an idea on how to get that info in a class:


ProfileCommon myProfile = (ProfileCommon)ProfileCommon.Create(HttpContext.Current.User.Identity.Name);


If you are using this in a web page code then you can directly use GetProfile method, like:

ProfileCommon myProfile = Profile.GetProfile(User.Identity.Name);


And then to get your LastName property, just use myProfile.LastName.


Love coding!

No comments: