C# 在连接字符串 web.config 成员提供程序之间交换
C# swap between connection strings web.config Membership provider
在应用程序中,我们有 2 个用于会员提供程序的连接字符串。
我们根据 2 个连接字符串及其属性创建用户:minRequiredNonalphanumericCharacters="2" minRequiredPasswordLength="8" maxInvalidPasswordAttempts="5"
用于用户,minRequiredNonalphanumericCharacters="1" minRequiredPasswordLength="6" maxInvalidPasswordAttempts="5"
用于管理员。
我们如何在创建用户或管理员时更改活动连接字符串?
代码
//Code needed to swap to User connection string
MembershipUser newUser = Membership.CreateUser(username, password, email, question, answer, isAproved, out cs);
Membership.UpdateUser(newUser);
Roles.AddUserToRole(username, "User");
//Code needed to swap to Admin connection string
MembershipUser newUserAdmin = Membership.CreateUser(usernameAdmin, passwordAdmin, emailAdmin, questionAdmin, answerAdmin, isAprovedAdmin, out cs);
Membership.UpdateUser(newUserAdmin);
Roles.AddUserToRole(usernameAdmin, "Administrator");
也许你可以试试:
var p = (SqlMembershipProvider)Membership.Providers["name_of_membership_provider"];
MembershipUser newUser = p.CreateUser(username, password, email, question, answer, isAproved, null, out cs);
p.UpdateUser(newUser);
在应用程序中,我们有 2 个用于会员提供程序的连接字符串。
我们根据 2 个连接字符串及其属性创建用户:minRequiredNonalphanumericCharacters="2" minRequiredPasswordLength="8" maxInvalidPasswordAttempts="5"
用于用户,minRequiredNonalphanumericCharacters="1" minRequiredPasswordLength="6" maxInvalidPasswordAttempts="5"
用于管理员。
我们如何在创建用户或管理员时更改活动连接字符串?
代码
//Code needed to swap to User connection string
MembershipUser newUser = Membership.CreateUser(username, password, email, question, answer, isAproved, out cs);
Membership.UpdateUser(newUser);
Roles.AddUserToRole(username, "User");
//Code needed to swap to Admin connection string
MembershipUser newUserAdmin = Membership.CreateUser(usernameAdmin, passwordAdmin, emailAdmin, questionAdmin, answerAdmin, isAprovedAdmin, out cs);
Membership.UpdateUser(newUserAdmin);
Roles.AddUserToRole(usernameAdmin, "Administrator");
也许你可以试试:
var p = (SqlMembershipProvider)Membership.Providers["name_of_membership_provider"];
MembershipUser newUser = p.CreateUser(username, password, email, question, answer, isAproved, null, out cs);
p.UpdateUser(newUser);