In my ASP.NET Web Forms app, I'm trying to create my own SQLMembershipProvider class, to override the ConnectionString at runtime. But I am getting a configuration error: "The type 'ExtendRegv1.MyMembershipProvider' is ambiguous"
I have created the following class in the App_code folder...
My Custom Membership Provider Class
namespace ExtendRegv1
{
public class MyMembershipProvider :SqlMembershipProvider
{
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
base.Initialize(name, config);
string connectionString = "Data Source=BSHEEHAN-PC\\SQLEXPRESS;Initial Catalog=ExReg_Default;Integrated Security=True";
FieldInfo connectionStringField = GetType().BaseType.GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
connectionStringField.SetValue(this, connectionString);
}
}
}
Web config:
<membership>
<providers>
<clear />
<add name="MyMembershipProvider" type="ExtendRegv1.MyMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="3" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
Thanks, Ben
I've just tried this out in a test project and it works fine for me. So couple of thoughts
When I put the class into App_Code I had to right click the file and in properties change the build action from Content to Compile - is was in VS 2010. This is unlikely to be your issue.
More likely - have you got two copies of MyMembershipProvider - i.e. is it also in a dll that is included in the build. It could even be someone elses demo code. I would comment out your app_code class and see if that builds. It won't fix it - just give you a good indication of what is wrong. I would be tempted to put the class in a dll anyway - but that just me (IMHO and all that)
Like I say - in classic developer speak - works for me on my build (it's like a motto almost!)