views:

605

answers:

1

I've written a custom MembershipProvider that uses a custom database schema for storing the members, but I am having trouble figuring out how to deploy the provider. My target server is running IIS7, and I am able to navigate to a dialog for a adding a .NET User Provider, but instead of allowing me to select the assembly containing the provider & then the class, it provides a drop-down with a couple of MS written providers.

Do I need to drop my assembly in a specific location so that my MembershipProvider class is discovered by IIS? If so, what where does the .dll need to go? Otherwise, how do tell ASP.Net to use my MembershipProvider? Every example I've seen simply references the fully qualified class name, but makes no mention of how the file needs to be deployed.

+5  A: 

If you look in the web.config file for your application, you should have a section called system.web. Within that there is a membership element with a list of providers. You should be able to add your provider and set a default provider there. Once your membership provider is registered in this way, you should be able to select it as a default for that application from IIS as well.

<system.web>
    ...
 <membership defaultProvider="MyMembershipProvider" 
                    userIsOnlineTimeWindow="15">
  <providers>
   <add name="MyMembershipProvider"
                             type="Common.Auth.MyMembershipProvider, Common" 
                             connectionStringName="MyAuthDBConnectionString" 
                             enablePasswordRetrieval="true" 
                             enablePasswordReset="true" 
                             requiresQuestionAndAnswer="true" 
                             writeExceptionsToEventLog="false" />
  </providers>
 </membership>
    ...
</system.web>

The providers element allows you to register multiple providers to choose from. Another feature is that you can clear out membership providers registered in other configuration files on the machine. This can make configuring your application less error prone later on. To do so, add the <clear/> element before the first membership provider (the <add/> element) in the list.

<system.web>
    ...
    <membership defaultProvider="MembershipProvider1">
        <providers>
            <clear />
            <add name="MembershipProvider1" ... />
            <add name="MembershipProvider2" ... />
        </providers>
    </membership>
    ...
</system.web>

If you want to register the same provider with multiple web applications just using IIS Manager, you will need to put the assembly in the GAC and add the provider to one of the machine config files instead. This is usually more work for little benefit when deploying a single application.

Chuck
You may also want to add a <clear/> just before the <add .... It will get rid of the other Membership providers that are inherited.
Lance Fisher