When you configure an ASP.NET Membership provider in web.config file, you can specify the "applicationName" attribute. Then, when you creating new users via this membership provider, the created user will be associated with the certain applicationName(you
set for this provider).
Thus, if you want to be able to create and manipulate users bound to multiple applicationNames(no matter they're stored in the same database or not), you need to configure multiple membershp providers in web.config. BTW, so far it seems there is no built-in API for you to change the "applicationName" of user after you have created it(you might need to manually change the table columns in database tables)
And in your code, you can use Membership.Providers property to reference all the providers you have configured in web.config. e.g.
var provider1 = Membership.Providers["NameOfProvider1"];
// use provider1 to manipulate users
jagjot
Contributor
2648 Points
1229 Posts
Role Management bind users to diffrerent applications
Apr 23, 2012 10:56 PM|LINK
Folks,
How can i bind users to different applicationsID's (in aspnetdb database).
I have 10 companies in one aspnetdb database. Want to bind users to their own companies..
Any ideas?
M.Sc, MIEEE, MCP, CCNA
Steven Cheng...
Contributor
4187 Points
547 Posts
Microsoft
Moderator
Re: Role Management bind users to diffrerent applications
Apr 25, 2012 04:30 AM|LINK
Hi jagjot,
When you configure an ASP.NET Membership provider in web.config file, you can specify the "applicationName" attribute. Then, when you creating new users via this membership provider, the created user will be associated with the certain applicationName(you set for this provider).
<membership defaultProvider="SqlProvider" > <providers> <clear /> <add name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MySqlConnection" ...... applicationName="MyApplication" ....... /> </providers> </membership>Thus, if you want to be able to create and manipulate users bound to multiple applicationNames(no matter they're stored in the same database or not), you need to configure multiple membershp providers in web.config. BTW, so far it seems there is no built-in API for you to change the "applicationName" of user after you have created it(you might need to manually change the table columns in database tables)
And in your code, you can use Membership.Providers property to reference all the providers you have configured in web.config. e.g.
#Membership.Providers Property
http://msdn.microsoft.com/en-us/library/system.web.security.membership.providers.aspx
here are some other web articles mentioned use multiple membership providers for in an ASP.NET web application.
#Using two Membership Providers for ASP.NET logins
http://www.stevideter.com/2008/03/20/using-two-membership-providers-for-aspnet-logins/
#Working with multiple membership and role providers
http://www.sitefinity.com/devnet/kb/sitefinity-3-x/working-with-multiple-membership-and-role-providers.aspx
Feedback to us
Microsoft One Code Framework
jagjot
Contributor
2648 Points
1229 Posts
Re: Role Management bind users to diffrerent applications
Apr 25, 2012 07:13 AM|LINK
Steven,
Thanks for your quick response. I am going to do bit of experimentation on your above solution and get back to you ASAP.
Cheers
M.Sc, MIEEE, MCP, CCNA
suresh dasar...
Contributor
3606 Points
743 Posts
Re: Role Management bind users to diffrerent applications
Apr 25, 2012 12:46 PM|LINK
hi jagjot
check this post
http://www.aspdotnet-suresh.com/2012/01/assign-or-remove-roles-to-users-in.html
Please "Mark as Answer" If post helps you
jagjot
Contributor
2648 Points
1229 Posts
Re: Role Management bind users to diffrerent applications
May 14, 2012 10:52 AM|LINK
Thanks Steven..
After my reaserch i also came to same conclusion - this is the best and robust technique available.
Surely this coud be better. I will write a class and db SP to sort this out and share with you..
Thank again...
M.Sc, MIEEE, MCP, CCNA