自定义RoleProvider未调用

时间:2012-02-07 15:58:26

标签: asp.net iis asp.net-membership membership-provider roleprovider

我的应用程序具有自定义角色和成员资格提供者。我已经在web.config中注册了它们,但是当我尝试if(User.IsInRole("Blah"))时,我在RoleProvider InitializeIsUserInRole中的任何断点都没有被击中。会员提供商工作正常,所以我想必须有一些我从web.config中遗漏的东西。这就是我所拥有的:

  <system.web>
    ...
    <membership defaultProvider="MyAppMembershipProvider" userIsOnlineTimeWindow="15">
    <providers>
      <clear />
      <add name="MyAppMembershipProvider" 
             type="MyAppMembership.MyAppMembershipProvider" 
             connectionStringName="MyApp" 
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" writeExceptionsToEventLog="false" />
      </providers>
    </membership>

    <roleManager defaultProvider="MyAppRoleProvider">
      <providers>
        <clear />
        <add name="MyAppRoleProvider"
             type="MyAppMembership.MyAppRoleProvider"
             connectionStringName="MyApp"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" writeExceptionsToEventLog="false" />
      </providers>      
    </roleManager>
  </system.web>

我还需要其他东西吗?

1 个答案:

答案 0 :(得分:8)

enabled的元素<roleManager> - 元素默认为false!尝试:

<roleManager enabled="true" defaultProvider="MyAppRoleProvider">
      <providers>
        <clear />
        <add name="MyAppRoleProvider"
             type="MyAppMembership.MyAppRoleProvider"
             connectionStringName="MyApp"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" writeExceptionsToEventLog="false" />
      </providers>      
    </roleManager>