简体   繁体   中英

create MembershipUser in different Db then is in web.config

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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM