473,395 Members | 1,696 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,395 software developers and data experts.

System.Web.Security.Roles.GetRolesForUser() is not returning the correct results

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 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 <membershipand
<roleManagerelements in my Web.config are as follows:

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

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

Everything that I have tried with Membership has given me no trouble, but
Roles seems to want to pretend that there are no roles, even though I have
added the roles using the ASP.NET Website Administration Tool, and even
looked directly at the database, so I know that the roles are there and are
associated with the users. Why am I able to use Membership but not Roles? I
would think that if there was a problem with the setup I would recieve an
Exception or error rather than just be returned an empty array. Any help
would be greatly appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Aug 8 '08 #1
2 5570
On Aug 9, 1:34*am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
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 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 <membershipand
<roleManagerelements in my Web.config are as follows:

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

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

Everything that I have tried with Membership has given me no trouble, but
Roles seems to want to pretend that there are no roles, even though I have
added the roles using the ASP.NET Website Administration Tool, and even
looked directly at the database, so I know that the roles are there and are
associated with the users. Why am I able to use Membership but not Roles?I
would think that if there was a problem with the setup I would recieve an
Exception or error rather than just be returned an empty array. Any help
would be greatly appreciated. Thanks.
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/
Hi Nathan

I am not very familiar with this but looking at the documentation I
see following:

- Only the roles for the application that is specified in the
ApplicationName property are retrieved.

- If CacheRolesInCookie is true, then the results of the
GetRolesForUser method may be returned from the role cache rather than
the specified role provider.

Does this tell you something?

http://msdn.microsoft.com/en-us/library/8ak75t41.aspx
Aug 9 '08 #2
The CacheRolesInCookie idea did cross my mind before, but I tried it again
anyway. I tried setting the CacheRolesInCookie="false" and deleting all my
browser cookies, but that did not help, so if caching is the problem, I am
still doing something wrong. I'm not sure what you meant by the
applicationName thing, but I do have that property set in my <add/element
in the Web.config. In case the value of this property confused you,
Membership is the name of my Web Application Project, which is why it is the
same in both the membership and roleManager element providers. I've
basically run out of ideas, so if anybody could help me, or even give a
suggestion to try, it would be greatly appreciated. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Alexey Smirnov" <al************@gmail.comwrote in message
news:61**********************************@k37g2000 hsf.googlegroups.com...
On Aug 9, 1:34 am, "Nathan Sokalski" <njsokal...@hotmail.comwrote:
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 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 <membershipand
<roleManagerelements in my Web.config are as follows:

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

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

Everything that I have tried with Membership has given me no trouble, but
Roles seems to want to pretend that there are no roles, even though I have
added the roles using the ASP.NET Website Administration Tool, and even
looked directly at the database, so I know that the roles are there and
are
associated with the users. Why am I able to use Membership but not Roles?
I
would think that if there was a problem with the setup I would recieve an
Exception or error rather than just be returned an empty array. Any help
would be greatly appreciated. Thanks.
--
Nathan Sokalski
njsokal...@hotmail.comhttp://www.nathansokalski.com/
Hi Nathan

I am not very familiar with this but looking at the documentation I
see following:

- Only the roles for the application that is specified in the
ApplicationName property are retrieved.

- If CacheRolesInCookie is true, then the results of the
GetRolesForUser method may be returned from the role cache rather than
the specified role provider.

Does this tell you something?

http://msdn.microsoft.com/en-us/library/8ak75t41.aspx
Aug 9 '08 #3

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

Similar topics

2
by: yawnmoth | last post by:
i'm using an entry in an sql database as a semaphore and it, unfortunately, doesn't appear to be working. the script that spawns the child processes has a for loop that performs the same basic sql...
1
by: Sam | last post by:
I have a desktop VB.Net application I developed locally. I uploaded it to a file server we have and the .Net Framework is installed on the file server. When I try to run the executable from the...
0
by: Andrzej | last post by:
Hi, I have to figure out why we have a problem with special characters in encrypted usernames and passwords. Case: Username: r&bgeorge Password: tigger
4
by: Earl T | last post by:
When I try to get the netscape version for version 7, I get the HttpBrowserCapabilities class returning the version as 5 and not 7. (see code and output below) CODE HttpBrowserCapabilities...
2
by: Andrew Banks | last post by:
Can anyone point me in the direction of a good tutorial/guido using security roles with forms authentication in C# I have an admin section to my website and would like two levels of admin. I'm...
6
by: alex | last post by:
Hi, this always works: private ConsoleToTextbox myConsole; Console.SetOut(myConsole); But now (a few weeks later i started this project again) i get a non handeld security exception from...
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: Nathan Sokalski | last post by:
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.