2

What I have tried so far:

I placed a Web.config in a folder I want to protect with the following content which should grant access to admin, second_level and third_level users only.

<?xml version="1.0"?>
<configuration>
  <system.web>
    <authorization>
      <allow roles="admin"/>
      <allow roles="second_level"/>
      <allow roles="third_level"/>
      <deny roles="first_level"/>
      <deny roles="blocked"/>
      <deny users="*" />
    </authorization>
  </system.web> 
</configuration>

In the main Web.config I put:

<roleManager enabled="true" defaultProvider="myapp.App_Code.SecurityAppRoleProvider" cacheRolesInCookie="true" createPersistentCookie="false" cookieProtection="All">
  <providers>
    <clear />
  </providers>
</roleManager>

The custom role provider:

 namespace myapp.App_Code
{
    public class SecurityAppRoleProvider : System.Configuration.Provider.ProviderBase
    {
        public SecurityAppRoleProvider()
        {
            var i = 0; // breakpoint here will never be reached?
        }

    }
}    

At this point there are some things I am struggling with:

  1. The <deny users="*" /> works. The ASP.NET app redirects me to the login page which is the beahvior I need. But the roles are are not considered by web application. Which means all users are currently blocked to access the page even if they are member of role admin.
  2. SecurityAppRoleProvider will never be instanced so I guess I need to register the custom role provider else where?
  3. Is not there a default Role Provider which should be used in connection with ASP.Net Identity Framework without code a custom one?
Stephan Ahlf
  • 3,310
  • 5
  • 39
  • 68

1 Answers1

0

I put this into main Web.config to solve the issue.

<roleManager enabled="true">
  <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnection" applicationName="/your-app-name"/>
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/your-app-name"/>
  </providers>
</roleManager>
Stephan Ahlf
  • 3,310
  • 5
  • 39
  • 68