-1

I have a MVC 5 Project.

I want to use Roles.GetAllRoles().

But i get the System.Configuration.Provider.Exception.

I tryed to solve it with modifying the Web.Config, but i still get the error.

<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<roleManager defaultProvider="CustomRoleProvider">
  <providers>
    <clear />
    <add name="CustomRoleProvider" type="MyProjekt.CustomRoleProvider" />
  </providers>
</roleManager>    
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.1" />

I also tryed to add

<roleManager 
enabled="true" 
cacheRolesInCookie="true" >

but then i get

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code

Additional information: No Connection with SQL Server-Database.

teo van kot
  • 12,350
  • 10
  • 38
  • 70
Olias
  • 401
  • 5
  • 17

2 Answers2

0

I got caught out by this for a while Roles.IsUserInRole("Admin") which sent me down the route of looking for role providers etc. I should of just been using User.IsInRole("Admin")
the following was a usefull article in enabling roles http://geekswithblogs.net/MightyZot/archive/2014/12/28/implementing-rolemanager-in-asp.net-mvc-5.aspx

user1158280
  • 29
  • 1
  • 2
  • 7
0

I know this maybe does not pertain specifically to your question, but I just discovered how to find the Role a particular User is assigned to:

    Dim userInfo = UserManager.FindById(User.Identity.GetUserId())
    Dim userRole As String = userInfo.Roles(0).RoleId
    Dim thisRole As String = db.Roles.Where(Function(x) x.Id = userRole).FirstOrDefault().Name

That was bugging me for a while so I just had to get it out there!

Andy
  • 616
  • 11
  • 32