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

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

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.
 
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

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.
 
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
(e-mail address removed)
http://www.nathansokalski.com/

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

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.
 
Back
Top