开发者

create MembershipUser in different Db then is in web.config

开发者 https://www.devze.com 2022-12-22 02:00 出处:网络
MembershipUser newUser = Membership.CreateUser(UsernameTextbox.Text, PasswordTextbox.Text); In web.config i have 开发者_开发技巧connection string but i would like to use MemBershipUser on different
MembershipUser newUser = Membership.CreateUser(UsernameTextbox.Text, PasswordTextbox.Text);

In web.config i have 开发者_开发技巧connection string but i would like to use MemBershipUser on different connection string. Is that possible, and if yes how?

regards


Just add an extra connectionstring and use that in your membership configuration. Look at this example: http://msdn.microsoft.com/en-us/library/6e9y4s5t.aspx As you can see, the membership section references its connection string by name.


found the solution if someone else has similar problem:

A simpler, albeit somewhat eyebrow-raising solution is just modifying the connection string in the providers early enough in the request's lifecycle:

      private void SetProviderConnectionString(string connectionString)
    {
        // Set private property of Membership, Role and Profile providers.
        var connectionStringField = Membership.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
        if (connectionStringField != null)
            connectionStringField.SetValue(Membership.Provider, connectionString);

        var roleField = Roles.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
        if (roleField != null)
            roleField.SetValue(Roles.Provider, connectionString);

        var profileField = ProfileManager.Provider.GetType().GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
        if (profileField != null)
            profileField.SetValue(ProfileManager.Provider, connectionString);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号