Reputation: 3280
I am using SQL server2012 database in with default ASP.net Membership. I have To Applications in the aspnet_applications table.
Let A and B
From One application in the Web Project i am creating user for the second Application.which will store in the aspnet_users table
Let From Application A from web i am creating the user for Application B
using the following code
Membership.ApplicationName = "B";
MembershipUser user = Membership.CreateUser(username, Membership.GeneratePassword(7, 2), email);
And after creting this new user i am not able to access the Current Application (Application A) until i restart the project.
So what is the problem here?
How can i add user to another application ?
Thanks
Upvotes: 1
Views: 612
Reputation: 62260
Membership.ApplicationName = "B";
means you switch the application name in runtime.
Actually, you want to call a provider by name. Then create a user using the provider.
MembershipProvider membershipProvider =
Membership.Providers["BMembershipProvider"];
Guid userId = Guid.NewGuid();
MembershipCreateStatus status;
membershipProvider.CreateUser("johndoe", "password",
"[email protected]", "question", "answer", true, userId, out status);
if (status == MembershipCreateStatus.Success)
{
MembershipUser user = membershipProvider.GetUser(userId, false);
// Optional - assign the user to roles
RoleProvider roleProvider = Roles.Providers["SiteBRoleProvider"];
roleProvider.AddUsersToRoles(new[] {user.UserName}, new[] {"Admin"});
}
Make sure you have both Membership Providers in web.config
<membership defaultProvider="AMembershipProvider">
<providers>
<add name="AMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider ..."
connectionStringName="DefaultConnection" ... />
<add name="BMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider ..."
connectionStringName="DefaultConnection" ... />
</providers>
</membership>
Upvotes: 1