Enabling Roles Using a Custom Membership Provider

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

  1. 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.
     
    , Feb 8, 2006
    #1
    1. Advertising

  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
    http://www.leastprivilege.com

    > 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.
    >
     
    Dominick Baier [DevelopMentor], Feb 8, 2006
    #2
    1. Advertising

  3. Guest

    Thanks, that cleared it up.

    "Dominick Baier [DevelopMentor]" wrote:

    > 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
    > http://www.leastprivilege.com
    >
    > > 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.
    > >

    >
    >
    >
     
    , Feb 8, 2006
    #3
  4. 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?

    "Dominick Baier [DevelopMentor]" wrote:

    > 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
    > http://www.leastprivilege.com
    >
    > > 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.
    > >

    >
    >
    >
     
    John Toop, Jun 5, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bGFuZW0=?=
    Replies:
    0
    Views:
    734
    =?Utf-8?B?bGFuZW0=?=
    Oct 21, 2005
  2. sloan
    Replies:
    5
    Views:
    1,515
    sloan
    Jun 4, 2006
  3. Replies:
    0
    Views:
    750
  4. sloan
    Replies:
    1
    Views:
    515
    Chad Scharf
    Jul 3, 2007
  5. Brett Ossman

    Custom Membership Provider - Custom Error Messages

    Brett Ossman, Mar 11, 2009, in forum: ASP .Net Security
    Replies:
    0
    Views:
    791
    Brett Ossman
    Mar 11, 2009
Loading...

Share This Page