未调用自定义 RoleProvider

发布于 2025-01-03 11:53:50 字数 1275 浏览 0 评论 0原文

我的应用程序有自定义 Role 和 MembershipProviders。我已在 web.config 中注册了它们,但是当我尝试执行 if(User.IsInRole("Blah")) 时,RoleProvider 的 Initialize 中的两个断点都没有或 IsUserInRole 被点击。会员资格提供程序工作正常,所以我想一定是我在 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>

还有我需要的东西吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻泪 2025-01-10 11:53:50

-Element 的属性 enabled 默认为 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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文