How can I debug a 'Default Membership Provider could not be found' error with WCF and a Custom ASP.NET membership provider?

StackOverflow https://stackoverflow.com/questions/2325688

Question

This is problem for me with .Net 3.5 SP1 running on IIS7.5 64 bit (I tried forcing 32 bit but got the same result).

I have a WCF service that I want to use authentication-services with. When I have no behavior the WCF service paints (replies) without any error. Other services also work with other behaviors

As soon as I add userNameAuthentication to the behaviour specifying a custom MembershipProvider for authentication to a service ...

  <serviceCredentials>
    <!-- Configure user name authentication to use the Membership Provider -->
    <userNameAuthentication userNamePasswordValidationMode ="MembershipProvider"
                            membershipProviderName ="MembershipService"/>
  </serviceCredentials>

The service blows up and returns the following error:

 Parser Error Message: Default Membership Provider could not be found.
 Source Error: 
 Line 49:     </authentication>
 Line 50:     
 Line 51:     <membership defaultProvider="MembershipService" userIsOnlineTimeWindow="15">
 Line 52:       <providers>
 Line 53:         <clear/>

Event Log has this error:

 WebHost failed to process a request.
 Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/59884855
 Exception: System.ServiceModel.ServiceActivationException: The service '/V4Service.svc' cannot be activated due to an exception during compilation.  The exception message is: Default Membership Provider could not be found. (C:\Code\SmartTrade Projects\SmartTrade.API\Web\SmartTrade.API\web.config line 50). ---> System.Configuration.ConfigurationErrorsException: Default Membership Provider could not be found. (C:\Code\SmartTrade Projects\SmartTrade.API\Web\SmartTrade.API\web.config line 50)
 at System.Web.Security.Membership.Initialize()
 at System.Web.Security.Membership.get_Providers()
 at System.ServiceModel.Configuration.UserNameServiceElement.ApplyConfiguration(UserNamePasswordServiceCredential userName)
 at System.ServiceModel.Configuration.ServiceCredentialsElement.ApplyConfiguration(ServiceCredentials behavior)
 at System.ServiceModel.Configuration.ServiceCredentialsElement.CreateBehavior()
 at System.ServiceModel.Description.ConfigLoader.LoadBehaviors[T](ServiceModelExtensionCollectionElement`1 behaviorElement, KeyedByTypeCollection`1 behaviors, Boolean commonBehaviors)
 at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
 at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
 at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
 at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
 at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses)
 at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
 at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
 at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
 at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)

I'm pretty sure this isn't an issue with the provider or provider config as I have this custom provider working with an ASP MVC site.

Any thoughts?

Was it helpful?

Solution

I started a new Custom Provider implementation from scratch ensuring all the overrides were correctly returning. My original one that I thought was working (that was a couple of months ago) and it turns out it no longer worked.

It turns out if you have the Provider Name correct and the Type correct in configuration that only leaves your Custom Provider implementation.

So if you have this issue and you are sure your config is correct, verify your implementation with a simple ASP.net or ASP.net MVC website.

OTHER TIPS

I got this error and eventually discovered that hidden UTF8 or Unicode characters had found their way into my web.config file. I had to delete sections to figure out that the application strings section was corrupted.

Once I replaced it from an older version, it worked again. Some of the strings had extra white space in them that was suspect, I am not sure if it could have been from cut and paste or what. You can try looking at your web.config file with a hex editor too.

I had this same problem and spent almost a week figuring it out. My problem was that I had to set the Name property override to the same value that was in the web.config's provider name. I hate it when the simplest solutions are so hard to find!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top