Category nameļ¼šProfile

Profile / ProfileBase SetPropertyValue

Just fixed a very nasty bug in one of the applications I’m developing. In the database world there is a name for this bug which at the moment does not come up in my mind, I think it is called a ‘lost write’ but I’m not sure.

Somewhere in a class I did the following based on a passed username:

var profile = ProfileBase.Create(username);
profile.SetPropertyValue(“test”, value);
profile.Save();

This code (by accident) was fired by the same user that requested the page. ASP.NET’s default behavior for profiles is that it loads the current user profile at page start and saves it at the end. And here lies my problem!

The code above first writes the updated “test” value but then the page overwrites it with the old version which looks like nothing had happened.

So the lesson learned today is to first check if the current user is the same user I want to modify the profile for and if so use the profile instance from HttpContext.Profile. Another lesson learned is that ASP.NET profiles don’t use optimistic concurrency control to prevent such write patterns.

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta