简体   繁体   中英

Custom Role Provider with Windows Authentication

We have a custom role provider in an ASP.NET web forms intranet site. We have made sure to have this class inherit from RoleProvider and implement the appropriate methods. However, it is clear that its methods are not being called, including Initialize. We have the following in web.config:

<authentication mode="Windows" />

<authorization>
    <allow roles="CRM"/>
    <deny users="?"/>
</authorization>

<roleManager defaultProvider="MyRoleProvider"
    enabled="true"
    cacheRolesInCookie="true">
    <providers>
        <clear />
        <add
            name="MyRoleProvider"
            applicationName="MyApp"
            type="MyApp.MyRoleProvider"
            writeExceptionsToEventLog="false" />
    </providers>
</roleManager>

It should be noted that we have reviewed this question, but its answer does not apply to our situation.

I feel like a fool having to provide this answer, but hopefully it might help someone out who's having similar trouble. While it seemed that all evidence pointed to the custom role provider not being called, it actually was. It appeared that it wasn't being called due to our roles being cached. As you can see in the snippet above, we had the following:

cacheRolesInCookie="true">

This caused the role manager to pull roles that we did not expect, as we were manipulating them during testing. When we changed the property to "false", everything began working as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM