Last post Nov 27, 2009 04:50 AM by Jerry Weng - MSFT
Nov 23, 2009 05:27 PM|JohnPadilla|LINK
I have seen responses to this question but none of the solutions seem to work in my case.
I have developed a custom class that overrides membership/role provider methods. This class inherits from: System.Web.Security.RoleProvider. This was required so that i could use it in an asp.net application via a web service.
This class has references to 2 web service (aspx) and these are called MembershipProvider and RoleProvider respectively. These services trick asp.net from what is in the web.config (this is listed later) This is how the Wrapper Class is initiated:
service = new Custom_Web_Membership_Providers.MembershipProvider.MembershipProvider();
I dont do anything special to any of the overridden methods. here is a sample of one of them:
public override void UpdateUser(MembershipUser user)
service.UpdateUser(_RemoteProviderName, _ApplicationName, ConvertUser(user));
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
if (config["roleProviderUri"] != null)
service.Url = config["roleProviderUri"];
_ApplicationName = config["applicationName"];
_ApplicationName = ProviderUtility.GetDefaultAppName();
_RemoteProviderName = config["remoteProviderName"];
DAL.DBDirectBase objDal = new DAL.DBDirectBase();
string connectionString = objDal.AdapterConnectionString("My_Membership_DB", true);
// Set private property of Role provider.
FieldInfo connectionStringField = typeof(SqlRoleProvider).GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
if (connectionStringField != null)
However when the connectionStringField.SetValue(this, connectionString); line gets called i get this error:
<membership defaultProvider="My_COM_MembershipProvider" userIsOnlineTimeWindow="30">
When i wrote this code about 2 years ago i didnt need to worry about the connection strings at runtime. now i need to be able to dynamically change the conenctionstring at runtime which means i dont really need the web.config's connectionstring but its required
for asp.net to run properly at startup
1. Is this is error is throwing because the code thinks the web service is the actual provider and there is no field called "_sqlConnectionString" there? I am not sure where i need to put the code to override the connectionstring
in my case.
2. Is there a way i can not need to rely on the web.config what so ever for the membership code? meaning not have to use web service as wrappers to satisfy the web config and have my membership code in my main project use just the membership class that overrides
I really don't want to recode how the membership provider stuff that MS does as this would be a major undertaking.
Thanks in advance!
Membership Connctionstring Override Change Runtime
Nov 27, 2009 04:50 AM|Jerry Weng - MSFT|LINK
Could you say more clearly about your problem?
But, according to my understanding, I think the document could help you find some clues to resolve your problem.
Building Custom Providers for ASP.NET 2.0 Membership