views:

63

answers:

1

I have created two custome membership providers that I would like to add to my web.config. The first one would be the default that the asp.net application would use. The second would be called by a WCF service that I have in the same application.

The providers in the membership section of my web.config looks like the following:

    <add name="SiteProvider" type="MyNameSpace.SiteProvider, MyNameSpace" ApplicationName="Si2" EnablePasswordReset="true" PasswordStrengthRegularExpression="(?=[\w$#_ ]{8,})(?=.*?\d)(?=.*?[A-z])[\w$#_ ]*" ResetPasswordMinimumLength="8" ResetPasswordPattern="USL9SLU9SLU9SLLLL" ResetPasswordAllowDuplicateCharacters="false" />
    <add name="WCFProvider" type="MyNameSpace.WCFProvider, MyNameSpace" ApplicationName="Si2" EnablePasswordReset="true" PasswordStrengthRegularExpression="(?=[\w$#_ ]{8,})(?=.*?\d)(?=.*?[A-z])[\w$#_ ]*" ResetPasswordMinimumLength="8" ResetPasswordPattern="USL9SLU9SLU9SLLLL" ResetPasswordAllowDuplicateCharacters="false" />

I receive the error "Item has already beed added. Key in dictionary: 'SiteProvider' Key being added: 'SiteProvider'" any time I browse to the site.

This doesnt make sense to me sense they have unique names. If i remove the second provider the site is browseable.

Any help on adding this second provider would be appreciated.

A: 

The simplest solution would be to move the webservice into a different project.

Also, make sure you call <clear/> before adding providers and include a default one...

<membership defaultProvider="Siteprovider">
    <providers>
        <clear/>
        <add name="SiteProvider" type="MyNameSpace.SiteProvider, MyNameSpace" ApplicationName="Si2" EnablePasswordReset="true" PasswordStrengthRegularExpression="(?=[\w$#_ ]{8,})(?=.*?\d)(?=.*?[A-z])[\w$#_ ]*" ResetPasswordMinimumLength="8" ResetPasswordPattern="USL9SLU9SLU9SLLLL" ResetPasswordAllowDuplicateCharacters="false" />
        <add name="WCFProvider" type="MyNameSpace.WCFProvider, MyNameSpace" ApplicationName="Si2" EnablePasswordReset="true" PasswordStrengthRegularExpression="(?=[\w$#_ ]{8,})(?=.*?\d)(?=.*?[A-z])[\w$#_ ]*" ResetPasswordMinimumLength="8" ResetPasswordPattern="USL9SLU9SLU9SLLLL" ResetPasswordAllowDuplicateCharacters="false" />
    </providers>
</membership>

You could try the solution in this forum post: http://forums.asp.net/p/1112089/1714276.aspx

Have you tried putting a separate web.config file in the webservice folder? I doubt that it will work, but it might be worth a try.

Daniel Dyson
Daniel, I do have this in a seperate project but I am publishing it out into the same directory because I would like it to share the resources of the web application. The code that you have is exactly what I have and get the error message expalined above. The link you provided doesnt give me quite what I want. I thought I would have the ability to add the second provider and point the WCF service to it all in the web.config without creating any code. Is this possible?
Evan
Tht could be your problem. I think you should publish your webservice project to a sub-directory of your site. Set it up as a virtual directory in IIS and enable it for webservices.
Daniel Dyson
So is it not possible to add more than one provider per application? It seems like I have seen other people doing it like these guys. http://www.sitefinity.com/help/developer-manual/implementing-multiple-membership-providers.html
Evan
I have had a look, and there seems to be a few examples like that one. So it must be possible. And the MSDN docs say you can, but helpfully doesn't show you how. Could it be that you are missing a connectionStringName from you provider settings?
Daniel Dyson
The original provider never had a connection string name as this is handled in the code of the custom provider that is configured via enterprise library. I am clearly missing something that seperates the two, but have not discovered what it could be.
Evan
I figured out the problem. In the code the Name property of the custom membership provider was overridden and hardcoded to a string. I needed to override it in my new class and have it produce a string that was different from the first one. Thanks Daniel for your help.
Evan