我正在创建一个 MVC4 多租户站点,该站点为每个租户使用单独的数据库,并且一直试图让会员资格为每个租户工作,但没有任何运气。
出于某种原因,无论我做什么,connectionStringField 始终为空。任何想法为什么会发生这种情况?
public class CodeFirstMembershipProvider : MembershipProvider
{
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
base.Initialize(name, config);
// hard coded for testing
string connectionString = @"server=localhost;database=masterdb;uid=master;pwd=password";
// Set private property of Membership provider.
FieldInfo connectionStringField = GetType().BaseType.GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
if(connectionStringField != null)
connectionStringField.SetValue(this, connectionString);
}
}