Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Multiple MembershipProvider and RoleProviderMultiple MembershipProvider and RoleProvider
Previous
 
Next
New Post
12/10/2012 4:03 PM
 

We have two existing website webA and webB. They use different custom membershipprovider and roleprovider. webA's user and role tables are in database A and webB's user and role tables are in database B. 

Now we are trying to use DotNetNuke for content management on both websites, ideally store the content management tables in a separate database, database C. What's the best way to accomplish this and utilize the existing custom MembershipProviders and RoleProviders?

Thanks,

Jason

 
New Post
12/11/2012 3:13 AM
 
DNN uses its own role management, but you might be able to create a tweaked membership provider for user authentication from a different database.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
New Post
12/11/2012 2:30 PM
 

Thanks for the reply. I think I should provide some details as how I solved (I hope) the problem. Hope it can help other people looking for an answer on the same question.

MembershipProvider is not a problem. I can just user Membership.Providers[ProviderName].ValidateUser. That's it.

For RoleProvider, there is a nice post here that explains how to set the RoleProviderName in a cookie and retrieve it later on. 

So my solution is:

  1. Create a new custom RoleProvider, which will be used as the default RoleProvider for the DotNetNuke website, which may contain multiple portals.
  2. Keep the definition for the DotNetNuke RoleProvider in web.config, but it's not the default anymore.
  3. In my case, I am trying to integrate two websites. For each website, define a RoleProvider in web.config. 
  4. Each website has its own login page. In the login button click event, set the cookie as describe in the above link.
  5. In the new custom RoleProvider, read the RoleProviderName from the cookie, and get the RoleProvider from Roles.Providers[RoleProviderName] and overwrite each of the methods, such as GetRolesForUser, IsUserInRole.

Web.config roleManager:

<roleManager defaultProvider="DefaultRoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
        <add name="DefaultRoleProvider" type="MultiRoleProviderWebsite.DefaultRoleProvider" connectionStringName="dbConnStr" applicationName="Application0" />
        <add name="RoleProvider1" type="MultiRoleProviderWebsite.RoleProvider1" connectionStringName="dbConnStr" applicationName="Application1" />
<add name="RoleProvider2" type="MultiRoleProviderWebsite.RoleProvider2" connectionStringName="dbConnStr" applicationName="Application2"/>
</providers>
</roleManager>


New DefaultRoleProvider class:

public class DefaultRoleProvider : SqlRoleProvider
    {
        public DefaultRoleProvider()
        {
        }

        private RoleProvider Provider
        {
            get
            {
                string providerName = GetProviderName();
                RoleProvider provider = null;
                if (!string.IsNullOrEmpty(providerName))
                    provider = Roles.Providers[providerName];
                else
                    provider = Roles.Provider;

                return provider;
            }
        }

        public string CustomProviderName
        {
            get
            {
                return Provider.Name;
            }
        }

        public override string[] GetAllRoles()
        {
            return Provider.GetAllRoles();
        }

        public override bool RoleExists(string roleName)
        {
            return Provider.RoleExists(roleName);
        }

        public override string[] GetRolesForUser(string username)
        {
            return Provider.GetRolesForUser(username);
        }

        public override string[] GetUsersInRole(string roleName)
        {
            return Provider.GetUsersInRole(roleName);
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            return Provider.IsUserInRole(username, roleName);
        }

        private string GetProviderName()
        {
            HttpCookie authCookie = HttpContext.Current.Request.Cookies["ANewCookie"];

            if (authCookie != null)
            {
                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

                if (!string.IsNullOrEmpty(authTicket.UserData))
                {
                    string[] parts = authTicket.UserData.Split('=');

                    if (parts.Length == 2 && parts[0] == "Provider")
                    {
                        return parts[1];
                    }
                }
            }

            return "";
        }
    }


 
New Post
12/12/2012 3:52 AM
 
AFAIK DNN does not call role management using the provider, i.e. your approach might fail.

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
Previous
 
Next
HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...Multiple MembershipProvider and RoleProviderMultiple MembershipProvider and RoleProvider


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out