5

I'm using Roles.GetRolesForUser() and when I call it I get {string[0]}. However, when I type in a users name as a hard coded string like this: Roles.GetRolesForUser("theloggedinusersname"), I get {string[2]} [0]: "AccountingAdmin" [1]: "Admin". For the record, I also get values for Roles.IsUserInRole and User.Identity.

Here is how I have my Web.config set up:

<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
    <providers>
        <clear/>
        <add connectionStringName="DefaultConnection" 
             applicationName="[MyAppName]" 
             name="DefaultRoleProvider" 
             type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[MyPublicKeyToken]" />
    </providers>
</roleManager>

Clue: "theloggedinusersname" is not equal to User.Identity.Name.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Aaron Salazar
  • 4,467
  • 10
  • 39
  • 54
  • what is the result of `Roles.GetRolesForUser(User.Identity.Name)`? – Damith Jun 18 '12 at 17:55
  • try looking at http://peterkellner.net/2006/10/20/loginfailswithiisnotcasini/ – jac Jun 18 '12 at 17:55
  • The result of `Roles.GetRolesForUser(User.Identity.Name)` is `{string[0]}` – Aaron Salazar Jun 18 '12 at 17:56
  • seems "theloggedinusersname" not equal to `User.Identity.Name` am i right? – Damith Jun 18 '12 at 18:00
  • Is User.Identity.Name equal to 'theloggedinusersname' (log in user)? I am asking this because GetRolesForUser call GetRolesForUser with HttpContext.User as a parameter. – Koste Jun 18 '12 at 18:01
  • Damith and Koste, you are correct, "theloggedinusersname" is not equal to User.Identity.Name. – Aaron Salazar Jun 18 '12 at 18:04
  • So, these two values are not equal. What does this mean? Am I pulling the wrong value from my database somehow? – Aaron Salazar Jun 18 '12 at 18:17
  • Are you using a Membership provider? Where are you getting "theloggedinusersname" from? – GWB Jun 18 '12 at 18:26
  • GWB, by "theloggedinusersname" I mean to say that if I type in the logged in user's name as a hard coded string into the Roles.GetRolesForUser() as a param then I get the appropriate roles returned for that user. – Aaron Salazar Jun 18 '12 at 18:31
  • @AaronSalazar OK, so how are you identifying the currently-logged-in user? Membership provider? Custom implementation? – GWB Jun 18 '12 at 18:34

0 Answers0