Can a web application use multiple Profile Providers?
I have a suite of web applications (web app projects, not web site projects) and all use the same membership database. Each application uses it's own app name in the membership, roles and profile provider configurations, which keeps the users unique to each application. This is by design, so that internal users and external users do not share login requirements and roles.
I also created one application with the sole purpose of managing access to the other applications in the suite. This "access manager" has a provider entry for each of the other app names in its configuration files, and has a main page with a drop down containing the available apps to manage. When the drop down is changed, the value sets the selected app name in session and that is used by a utility to return the appropriate provider.
So, for example purposes, I have three web apps: MyApplication1, MyApplication2 and AccessManager.
MyApplication1 and AccessManager share the same authentication and roles, MyApplication2 has different users/roles.
MyApplication1 is the default profile provider (SqlMembershipProvider, SqlRoleProvider, SqlProfileProvider) in AccessManager.
Example:
public static MembershipProvider SelectedMembershipProvider
{
get
{
string appName = HttpContext.Current.Session["appName"] as string;
if (String.IsNullOrEmpty(appName)) appName = "MyApplication1";foreach (MembershipProvider provider in Membership.Providers)
{
if (provider.ApplicationName == appName) return provider;
}return null;
}
}
I have a reason for using the appname instead of the provider name.
Anyway - this method works great for membership users and roles. However, switching the profile provider is not so straight forward. I created the recommended ProfileCommon class for web app projects, and it works just fine for getting/setting profile values for the default (MyApplication1) profile provider. But I cannot get profile values for MyApplication2.
I am able to get a "SelectedProfileProvider" like the sample above, but I can't figure out how to get to the profile values for a user. I would also like to be able to support different profiles for the different apps (ie. MyApplication2 has properties that MyApplication1 does not), so the ProfileCommon class is not my preferred method of supporting profiles in AccessManager.
Here is the profile config in AccessManager for the example:
<profile defaultProvider="MyApplication1SqlProfileProvider" inherits="AccessManager.ProfileCommon">
<providers>
<clear />
<add name="MyApplication1SqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="AccessManager.SQL"
applicationName="MyApplication1" /><add name="MyApplication2SqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="AccessManager.SQL"
applicationName="MyApplication2" />
</providers>
</profile>
I only need to get/display profile property values in the AccessManager app, not update them. Is there a way to support this scenario without creating a custom provider?- MovidoJialiang Ge [MSFT]MSFTquinta-feira, 5 de novembro de 2009 9:04offtopic (From:.NET Base Class Library)
Todas as Respostas
- Hello
This forum does not cover ASP.NET questions. Please post it to the ASP.NET forum:
http://forums.asp.net/
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

