473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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 <roleManagerelement 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
nj********@hotmail.com
http://www.nathansokalski.com/
Aug 3 '08 #1
2 5102
On 3 Aug, 02:49, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
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 <roleManagerelement 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
njsokal...@hotmail.comhttp://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.
Aug 5 '08 #2
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
nj********@hotmail.com
http://www.nathansokalski.com/

"Stan" <go********@philhall.netwrote in message
news:01**********************************@f36g2000 hsa.googlegroups.com...
On 3 Aug, 02:49, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
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 <roleManagerelement 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
njsokal...@hotmail.comhttp://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.
Aug 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ben R. | last post by:
Hi, The documentation for RoleProvider.IsUserInRole states: "The IsUserInRole method is called by the IsUserInRole method of the Roles class and the IsInRole method of the RolePrincipal class...
2
by: Jules | last post by:
When creating this website I user a custom authentication method to validate the usercredentials (I think the membership provider is an overkill since I only use the authentication part). When I...
1
by: xeroxero | last post by:
What is the fastest way to enumerate roles for an ASP.NET 2.0 user? Authentication and authorization has occurred, and roles have been assigned to my (Generic)Principal. I just want to list them to...
1
by: mazdotnet | last post by:
Hi, I have a GridView that I want to bind user roles to gvUserRoles.DataSource = Roles.GetRolesForUser("Username"); gvUserRoles.DataBind(); How can access the roles using <asp:GridView...
1
by: mazdotnet | last post by:
Hi, I have a GridView that I want to bind user roles to gvUserRoles.DataSource = Roles.GetRolesForUser("Username"); gvUserRoles.DataBind(); How can access the roles using
2
by: Jonathan Wood | last post by:
I've set up ASP.NET membership. I can get the role(s) of the current user by calling Roles.GetRolesForUser(). It seems like it would be a good idea to store some role-specific calculations in...
2
by: Nathan Sokalski | last post by:
When I call System.Web.Security.Roles.GetRolesForUser() it returns no results (an array of length 0) even though I have roles associated with the currently logged in user. I am able to get the...
11
by: giddy | last post by:
hi, (I want someone to check if my idea is utterly stupid or ok??) I have a mid complex app for a hotel that needs a fine grained user security system. In other words an admin should be able...
7
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I am using this code to get groups for a user and getting a error (5) on the GetAuthorizationGroups() function . There are two domains. This function works on the local domain but does not work...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.