kamagra how much to take

Quick Tip: Getting MembershipProvider for SPWebApplication

When constructing code leveraging the ASP.NET 2.0 membership model that SharePoint employs, you will in due course want to hydrate a System.Web.Security.MembershipProvider object. If you have written custom membership providers, this abstract class should already be recognizable with since its members are implemented in derived provider subclasses.

Ordinarily, you hydrate a strongly typed reference to a MembershipProvider object by providing an uncomplicated index operation on the Membership.Providers collection, austerely supplying the name of the provider:

  1. System.Web.Security.MembershipProvider memProvider = System.Web.Security.Membership.Providers["providername"];

Not very fancy :)

An alternative is viable to this by providing two strongly typed parameters, namely a SPWebApplication and SPUrlZone, to return the strongly typed MembershipProvider. To do this, we can use a comparable approach as above, executing an index on the Membership.Providers collection. However we can automate the retrieval of the provider name using the SPWebApplication.GetIisSettingsWithFallback method consuming the SPUrlZone parameter. Subsequently, the MembershipProvider can be queried:

  1. public static MembershipProvider BuildMembershipProvider(SPWebApplication app, SPUrlZone zone)
  2. {
  3. return Membership.Providers[app.GetIisSettingsWithFallback(zone).MembershipProvider];
  4. }
Share

One Comment

  1. Dan Kahler says:

    Awesome timing, Adam – I was planning to refactor some code this morning around my own ugly implementation! GetIisSettingsWithFallback will provide a much cleaner way to dynamically find the URL of a specific zone based on the configured authentication mode and membership provider, and I would have completely missed this method without your post.

Trackbacks/Pingbacks

  1. Links (3/4/2009) « Steve Pietrek - Everything SharePoint - [...] Quick Tip: Getting MembershipProvider for SPWebApplication [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>