私はProfileBase
たconnectionStringを変更するために使用する次のコードを、持っている:すべてのconnectionStringField
の第一は、常にnullとして戻ってくる変更ProfileBaseのConnectionString動的
ProfileBase profile = ProfileBase.Create(username);
string _connectionString = (_DataModel.Connection as System.Data.EntityClient.EntityConnection).StoreConnection.ConnectionString;
FieldInfo connectionStringField = profile.Providers["MySqlProfileProvider"].GetType().BaseType.GetField("_sqlConnectionString", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
connectionStringField.SetValue(profile.Providers["MySqlProfileProvider"], _connectionString);
profile["FirstName"] = firstName;
profile["Surname"] = surname;
profile.Save();
、しかし私はprofile.Providers
が含まれていないことがわかりますがMySqlProfileProvider
。これは私のWeb.Config
内に指定されています
<profile defaultProvider="MySqlProfileProvider">
<providers>
<clear/>
<add name="MySqlProfileProvider" connectionStringName="MyApp" applicationName="MyApp" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
<properties>
<add allowAnonymous="false" defaultValue="" name="FirstName" readOnly="false" serializeAs="String" type="System.String"/>
<add allowAnonymous="false" defaultValue="" name="Surname" readOnly="false" serializeAs="String" type="System.String"/>
</properties>
</profile>
私の質問はどのようにconnectionStringField
が来るヌルとして戻って来ているのですか?これは、通常MembershipProvider
のInitialize
メソッドをオーバーライドしてカスタムの場合のように接続文字列を変更できないということですか?あなたは1あまりにも多くのbasetypesを下った
ASP.NETのWebサイトまたはプロジェクトテンプレート? – IrishChieftain
@IrishChieftain ASP.NETプロジェクト(MVC with w/EF)。 – fuzz
FirstNameとSurnameのプロパティは戻っていますか? – IrishChieftain