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

  • Thread starter Nathan Sokalski
  • 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.
 
S

Stan

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

Nathan Sokalski

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top