System.Web.Security.Roles.GetRolesForUser() is returning no results

Discussion in 'ASP .Net' started by Nathan Sokalski, Aug 3, 2008.

  1. When I call System.Web.Security.Roles.GetRolesForUser() it returns no
    results even though I have roles associated with the currently logged in
    user. I am able to get the username by calling
    System.Web.Security.Membership.GetUser().UserName. Why am I unable to get
    the Roles, and what could I need to change? The <roleManager> element in my
    tag is as follows:

    <roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
    <providers>
    <add name="CustomizedRoleProvider"
    type="System.Web.Security.SqlRoleProvider"
    connectionStringName="logindb"
    applicationName="Membership"/>
    </providers>
    </roleManager>

    As you can see, I do have the enabled="true" attribute. Why am I having
    trouble using the System.Web.Security.Roles methods? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Aug 3, 2008
    #1
    1. Advertising

  2. Nathan Sokalski

    Stan Guest

    Re: System.Web.Security.Roles.GetRolesForUser() is returning noresults

    On 3 Aug, 02:49, "Nathan Sokalski" <> wrote:
    > When I call System.Web.Security.Roles.GetRolesForUser() it returns no
    > results even though I have roles associated with the currently logged in
    > user. I am able to get the username by calling
    > System.Web.Security.Membership.GetUser().UserName. Why am I unable to get
    > the Roles, and what could I need to change? The <roleManager> element in my
    > tag is as follows:
    >
    >     <roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
    >       <providers>
    >         <add name="CustomizedRoleProvider"
    >              type="System.Web.Security.SqlRoleProvider"
    >              connectionStringName="logindb"
    >              applicationName="Membership"/>
    >       </providers>
    >     </roleManager>
    >
    > As you can see, I do have the enabled="true" attribute. Why am I having
    > trouble using the System.Web.Security.Roles methods? Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    Nathan

    If Membership works OK then there is no need to for all the extra
    configuration for roles. The "CustomizedRoleProvider" name is probably
    not being recognised.

    Just put:

    <roleManager enabled="true" />

    The applicationName and connectionString will then be taken from the
    MemberShip section.
    Stan, Aug 5, 2008
    #2
    1. Advertising

  3. If I use <roleManager enabled="true" /> instead of what I had before, I
    receive the following error:


    An exception of type 'System.Web.HttpException' occurred in System.Web.dll
    but was not handled in user code

    Additional information: Unable to connect to SQL Server database.


    This error occurs on the following line of code:

    Dim roleslist As String() = System.Web.Security.Roles.GetRolesForUser()

    This is the first line of code that uses the System.Web.Security.Roles
    namespace, so I am assuming that <roleManager enabled="true"/> is not
    getting the connectionString from the Membership section. Here is what my
    Membership section in my Web.config file looks like, since I did not include
    it in my original posting:

    <membership defaultProvider="CustomizedProvider">
    <providers>
    <add name="CustomizedProvider"
    type="System.Web.Security.SqlMembershipProvider"
    connectionStringName="logindb"
    applicationName="Membership"
    minRequiredPasswordLength="8"
    minRequiredNonalphanumericCharacters="0"
    requiresQuestionAndAnswer="false"
    requiresUniqueEmail="false"/>
    </providers>
    </membership>

    Any other ideas? I appreciate all suggestions and help. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Stan" <> wrote in message
    news:...
    On 3 Aug, 02:49, "Nathan Sokalski" <> wrote:
    > When I call System.Web.Security.Roles.GetRolesForUser() it returns no
    > results even though I have roles associated with the currently logged in
    > user. I am able to get the username by calling
    > System.Web.Security.Membership.GetUser().UserName. Why am I unable to get
    > the Roles, and what could I need to change? The <roleManager> element in
    > my
    > tag is as follows:
    >
    > <roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
    > <providers>
    > <add name="CustomizedRoleProvider"
    > type="System.Web.Security.SqlRoleProvider"
    > connectionStringName="logindb"
    > applicationName="Membership"/>
    > </providers>
    > </roleManager>
    >
    > As you can see, I do have the enabled="true" attribute. Why am I having
    > trouble using the System.Web.Security.Roles methods? Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    Nathan

    If Membership works OK then there is no need to for all the extra
    configuration for roles. The "CustomizedRoleProvider" name is probably
    not being recognised.

    Just put:

    <roleManager enabled="true" />

    The applicationName and connectionString will then be taken from the
    MemberShip section.
    Nathan Sokalski, Aug 5, 2008
    #3
    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?QmVuIFIu?=

    Roles.IsUserInRole maps call to GetRolesForUser... Why?

    =?Utf-8?B?QmVuIFIu?=, Mar 20, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    875
    Steven Cheng[MSFT]
    Mar 24, 2006
  2. Nathan Sokalski
    Replies:
    2
    Views:
    1,567
    Nathan Sokalski
    Aug 9, 2008
  3. JaiPrakash Sharma

    Roles.GetRolesForUser(UserName) returning zero-dimension array

    JaiPrakash Sharma, Jan 30, 2008, in forum: ASP .Net Security
    Replies:
    1
    Views:
    218
    Misbah Arefin
    Feb 4, 2008
  4. Nathan Sokalski
    Replies:
    2
    Views:
    979
    Nathan Sokalski
    Aug 5, 2008
  5. Nathan Sokalski
    Replies:
    2
    Views:
    1,304
    Nathan Sokalski
    Aug 9, 2008
Loading...

Share This Page