Search code examples
asp.net-mvcroleprovider

My CustomRoleProvider doesn't seem to be used for controlling access to the application


I've set up my application to use a custom role provider by adding some lines to the Web.config file, like so:

<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
    <providers>
    <!--    <clear/>-->
        <add name="CustomRoleProvider"
            connectionStringName="Custom"
            applicationName="Custom"
            type="Authorization.CustomRoleProvider"  /> 
    </providers>
</roleManager>

I've created an empty Authorization.CustomRoleProvider class and added references to it.

Now my code has one simple test case in it, like so: [Authorize (Roles= "Admin")] public ActionResult Index(Model model)

As far as I can tell, none of the code I've written so far is being called (if it would, it would raise an exception on account of methods not being implemented). Am I messing something up in my configuration?


Solution

  • You should change your default provider name to match your provider name of "CustomRoleProvider":

    <roleManager enabled="true" defaultProvider="CustomRoleProvider">