Enabling Roles Using a Custom Membership Provider

Discussion in 'ASP .Net Security' started by EagleRed, Feb 8, 2006.

  1. EagleRed

    EagleRed Guest

    I have setup a custom membership provider for an ASP.NET 2.0 application as
    follows:

    <connectionStrings>
    <add name="MyDB" connectionString="Data Source=localhost;
    user id=myAppLogon;
    password=pppwwwddd;Initial Catalog=MyAppDB"
    providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
    <authentication mode="Forms" />
    <membership defaultProvider="myAppProvider">
    <providers>
    <add name="myAppProvider" connectionStringName="MyDB"
    ...
    type="System.Web.Security.SqlMembershipProvider"/>
    </providers>
    </membership>
    </system.web>

    I created MyAppDB using the aspnet_regsql utility and added some tables that
    have some relations with the tables it created. All has worked fine to this
    point.

    I now want to add roles. I went into the WAT and enabled roles. It added a
    roleManager line to the web.config file as follows.

    <system.web>
    <authentication mode="Forms" />
    <roleManager enabled="true" />
    <membership defaultProvider="myAppProvider">
    <providers>
    <add name="myAppProvider" connectionStringName="MyDB"
    ...
    type="System.Web.Security.SqlMembershipProvider"/>
    </providers>
    </membership>
    </system.web>

    I edited it to read,

    <roleManager enabled="true" defaultProvider="myAppProvider" />

    I added some roles which did not appear in MyAppDB and I cannot edit or
    manager users. The error says it cannot find the provider. What happen? How
    can it be fixed?

    As always, any help would be appreciated.
     
    EagleRed, Feb 8, 2006
    #1
    1. Advertisements

  2. Hi,

    role and membership are 2 different providers - you also have to register
    the role provider - the name "myAppProvider" is unknown to ASP.NET for roles.

    look at machine.config in the framework directory for the roleManager element
    and copy it to your local web.config (give it an appropriate name, change
    the connection string name etc...)
     
    Dominick Baier [DevelopMentor], Feb 8, 2006
    #2
    1. Advertisements

  3. EagleRed

    EagleRed Guest

    Thanks, that cleared it up.

     
    EagleRed, Feb 8, 2006
    #3
  4. EagleRed

    John Toop Guest

    Hi Dominick, Could I get some details on this? Does this mean that there
    needs to be a "provider" entry that corresponds to the "defaultprovider"
    defined within the "rolemanager" element? This seems to be where I'm getting
    hung up. I'm looking at the what EagleRed was trying to do but they seem to
    reference Membership provider and I'm trying to setup a "role" provider.

    I see (from machine.config) that there are definitions for two role
    providers;

    name="AspNetSqlRoleProvider"
    name="AspNetWindowsTokenRoleProvider"

    But, while I can understand the concept that my custom role provider is not
    going to have the same name as a "built in" role provider I do not know what
    to enter for the other attributes. My class handles the connection string.
    The "type" is the namespace but is a namespace the same as the class? The
    word "namespace" does not appear within my vb class. Does the
    "applicationName" need to correspond to the "ApplicationName" property of the
    RoleProvider defined within the class?
     
    John Toop, Jun 5, 2009
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.