Custom RoleProvider Not Called

岁酱吖の 提交于 2019-12-23 17:30:28

问题


My application has custom Role and MembershipProviders. I've registered them in web.config, but when I try to do if(User.IsInRole("Blah")), neither of my breakpoints in the RoleProvider's Initialize or IsUserInRole are hit. The membership provider works fine, so I guess there must be something I've missed from web.config. This is what I have:

  <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>

Is there something else which I need?


回答1:


The attribute enabled of the the <roleManager>-Element defaults to false! Try:

<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>


来源:https://stackoverflow.com/questions/9179466/custom-roleprovider-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!