2

I try to implement my own RoleProvider:

public class MyRoleManger : RoleProvider
{
    public override bool IsUserInRole(string username, string roleName)
    {
        throw new NotImplementedException();
    }

    public override string[] GetRolesForUser(string username)
    {
        throw new NotImplementedException();
    }
    private string appName = "";
    public override string ApplicationName
    {
        get { return appName; }
        set { appName = value; }
    }
....
}

It is my Web.config:

 <system.web>
       .....
        <roleManager defaultProvider="RoleManger" enabled="true" >
            <providers>
            <clear/>
                <add name="RoleManger" type="UserManager.Client.Web.MyRoleManger" applicationName="MyApp"/>
            </providers>
        </roleManager>

        <authentication mode="Windows"/>
        <identity impersonate="true"/>
    </system.web>

    <system.webServer >
        <security>
            <authorization >
                <clear/>
                <add accessType="Allow" roles="anyRole"/>
                <add accessType="Deny" users="?"/>
            </authorization>
        </security>
        ...
    </system.webServer >

But ASP.NET under IIS don't call MyRoleManager methos. Instead its try get "anyRole" from Windows Security Groups (AD). How to enforce IIS to use MyRoleManager with Windows Authentication?

MaxWave
  • 382
  • 2
  • 17
  • your role provider implementation should have a name property. make sure that it is set correctly as it pertains to your configuration. – Glenn Ferrie Jul 06 '11 at 11:21
  • What the Name property do you mean? The MyRoleManager.Name property? Or MyRoleManager.ApplicationName propery? Default implementation of RoleProvider dont have this property. – MaxWave Jul 06 '11 at 11:31
  • It may be obvious, but how are you getting roles? are you using the Roles class or user.IsInRole? – Simon Halsey Jul 06 '11 at 11:34
  • ApplicationName, I meant. The 'Name' property is on ProviderBase – Glenn Ferrie Jul 06 '11 at 11:34
  • ApplicationName is only relevant if your class uses it. the default uses the web app name if you don't set it – Simon Halsey Jul 06 '11 at 11:36
  • 2Simon Halsey - I get roles from my own way in method GetRolesForUser(). It's not important. But this method don't called on IIS – MaxWave Jul 06 '11 at 11:45
  • 1
    There is similar question http://stackoverflow.com/questions/2750215/custom-roles-in-asp-net, but the problem is solved "by hands" in AuthenticateRequest event. Can I avoid this code (only with web.config) and MyRoleManager? – MaxWave Jul 06 '11 at 11:53

0 Answers0