Today's documentationless experiment: Writing a ProfileProvider

Writing a Membership provider sure was easy, but wow is the documentation a bit thin for writing a Profile provider. I've started with the GetPropertyValues() method. So far I've got this bit working in a class called PopForumsProfileProvider, which inherits the abstract base class ProfileProvider:

public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection ppc)
{
 HttpContext.Current.Trace.Warn(context.ToString());
 string s = ppc.ToString();
 HttpContext.Current.Trace.Warn(s);
 SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();
 if ((bool)context["IsAuthenticated"])
 {
  People p = new People(context["UserName"].ToString(), PeopleLookupType.Name);
  SettingsPropertyValue list = new SettingsPropertyValue(ppc["PopForums.List"]);
  list.PropertyValue = p.List;
  settings.Add(list);
 }
 else throw new Exception("PopForums Profile provider: User is not currently authenticated.");
 return settings;
}

And in web.config...

<profile>
 <providers>
  <add name="PopForums" type="PopForums.Security.PopForumsProfileProvider, PopForums" />
 </providers>
 <properties>
  <group name="PopForums">
   <add name="List" type="System.Boolean" provider="PopForums" />
  </group>
 </properties>
</profile>

People is a class from my forum that manages user data. So far, this works like a champ. It took some debugging and poking around to figure out what the hell those two parameters were because the docs don't actually say at the moment.

The trick now is figuring out where in the page's event life cycle the SetPropertyValues() method of the provider is called. I guess it's not essential to know, but I would like to.

The other thing that I'm curious to know is how the default provider (which will be SqlProfileProvider in beta 2) iterates through the property collection. In the above code, I couldn't figure out exactly how to figure out what the property names were in ppc.

1 Comment

  • Jeff:



    The SetPropertyValues method is called when the Save method of the Profile class is called, by default this is done during the Application_EndRequest event. The Profile uses a HttpModule (ProfileModule) for the Profile feature. This hooks up to the AcquireRequestState event and the EndRequest event:



    Application_AcquireRequestState - When this event is executed, the Profile loads its data

    Application_EndRequest - When this event is executed, the Profile will save its data.





Comments have been disabled for this content.