Using Profiles in a Web Farm Scenario

In a Web farm scenario, each server provides a local profile cache. The value of the user's profile (UserObject profile) in a particular cache can become outdated if the profile was changed on a different server. In order for the server to recognize that the user's profile has changed, a last updated timestamp is set in both the user's profile (in the Profiles store) and in a cookie for the user, when the profile is created and updated (by using the UpdateUserProfile method).

When a user visits a server in the Web farm, the timestamp in the profile in the local cache is checked against the timestamp in the cookie (by using the GetCurrentUserProfile method). If they are not equal, the profile is retrieved from the Profiles store (by using the GetInfo method of the IADs interface), bypassing the local cache. If cookies are not enabled, the cache is always bypassed, because there is no reliable way of tracking the last updated time due to Back button, page refresh, and other issues.

The Profiling System caches the lookup of address profiles. Organization profile lookups, however, bypass the cache on an as-needed basis depending on the likelihood of the data in the profile changing.

Even with the timestamp solution, there are potential cache coherency issues with the profiles. For instance, if a user's profile, which is currently cached, is changed from the Business or Partner Desk on a different computer by a different user, the sites will not know that the cache is out of date. To mitigate this, the Solution Sites call the GetInfo method upon login. If this level of accuracy is not acceptable, the Solution Sites include the m_iGlobalProfileLookUpOption variable, declared in the file include\setupenv.asp, which when set always forces a GetInfo method call to retrieve the profile from the Profiles store.

The following function, EnsureUpToDateUserProfile from the Solution Sites, illustrates the core functionality of an implementation that addresses these issues. To view the full context of the code that addresses Web farm issues, review the code in the Solution Sites files login.asp and stdprofile_lib.asp.

Sub EnsureUpToDateUserProfile(ByRef rsUser)
   Dim sCookieTimeStamp, sCacheTimeStamp

   ' Since testing cookie support on every page that 
   ' calls UpdateUserProfile is
   ' expensive, we assume cookie support unless we detect a ticket in URL.
   If m_iTicketLocation <> 1 Then 
      sCookieTimeStamp = Request.Cookies("UserProfileTimeStamp")
      sCacheTimeStamp = CStr(rsUser.Fields("ProfileSystem.date_last_changed").Value)

         If (sCookieTimeStamp = "") Or (sCacheTimeStamp <> sCookieTimeStamp) Then
            Call GetProfileFromDB(rsUser)

            ' Set/update the cookie timestamp
               If rsUser Is Nothing Then
                  ' Delete the cookie for a deleted profile. 
                  Response.Cookies("UserProfileTimeStamp").Expires=Now - 1
          Response.Cookies("UserProfileTimeStamp") = 
               End If
         End If
            ' Get the current user's profile from the database
            ' if cookies are not supported.
            Call GetProfileFromDB(rsUser)
         End If
End Sub

See Also

Running the Profiles Resource

Using Profiles in Web Site Management

Profile Structure

Profile Definitions

Profile Properties

Profile Property Attributes

Collecting and Storing Profiles

Copyright © 2005 Microsoft Corporation.
All rights reserved.