The Role Manager feature has not been enabled but its enabled in config

1.4k Views Asked by At

I have created the following class for customized roleProvider in a folder called providers within my web project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Project.Providers
{
  public class MyCustomRoleProvider : System.Web.Security.SqlRoleProvider
  {
    public override string[] GetRolesForUser(string username)
    {
        string[] currentUserRoles = { "Admin", "User" };
        return currentUserRoles;
    }
  }
}

I have added the following section in the web.config:

<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
    <providers>
      <add name="DefaultRoleProvider" type="Project.Provider.MyCustomRoleProvider, MetaLearning"/>
    </providers>
  </roleManager>

When I try to add the following code on my home controller:

Roles.AddUserToRole("username","role");

I am receiving an error that The Role Manager feature has not been enabled. What am I doing wrong?

1

There are 1 best solutions below

0
On

Sometimes there are two web.config file in our project.Like in MVC4 internet application project one belongs in views folder This is not the configuration file for your application. It contains the configuration required to make views work with ASP.NET. Make sure you implement your requirements in correct web.config file.