簡體   English   中英

自定義角色提供程序緩存故障排除

[英]Custom role provider cache troubleshooting

我已經編寫了自定義角色提供程序,該提供程序在內部使用Web服務方法來獲取角色或用戶名。 此提供程序繼承自System.Web.Security.RoleProvider web.config文件中,我打開了.NET提供的使用cookie的緩存功能。

這是此提供程序的web.config部分的外觀:

<system.web>      
      <roleManager defaultProvider="MyProvider"
                 enabled="true"
                 cacheRolesInCookie="true"
                 cookieName=".MYROLES"
                 cookieTimeout="30"
                 cookiePath="/"
                 cookieRequireSSL="false"
                 cookieSlidingExpiration="true"
                 cookieProtection="All">
        <providers>
          <clear/>
          <add name="MYProvider"
               type="MYProvider.MyRoleProvider, MYProvider"
               Service1URL="http://localhost:54013/service1.asmx"
               Service2URL="http://localhost:54013/service2.asmx"
               rolesPrefix="ABC_"
               domainName="abc.corp"
               specialUserForAllRoles="abc"
               applicationURL="http://example.com"
               logCommunication="true"/>
        </providers>
      </roleManager>
</system.web>

現在,它來測試緩存是否正在工作。 我寫了一個簡單的方法,看起來像這樣:

public void TestCache()
{
   string[] roles = Roles.GetAllRoles();
   roles = Roles.GetAllRoles();

   string[] rolesForUser1 = Roles.GetRolesForUser("user1");
   rolesForUser1 = Roles.GetRolesForUser("user1");

   string[] usersInRole = Roles.GetUsersInRole("ABC_DEV");
   usersInRole = Roles.GetUsersInRole("ABC_DEV");       

   Roles.IsUserInRole("user1", "ABC_DEV");
   Roles.IsUserInRole("user1", "ABC_DEV");
}

在調試這段代碼時(從測試網站上),調試器將每個顯示的方法輸入提供程序並在其中執行所有邏輯,盡管方法歸納是否多余。 我認為不應執行每個方法的第二次調用,因為將返回結果,而無需直接從緩存中詢問我的提供程序。

我在做什么/認為有錯誤以及如何解決緩存功能?

問候

角色緩存僅適用於當前用戶的角色。 這應該被緩存:

var isInRole = User.IsInRole("ABC_DEV")

http://msdn.microsoft.com/zh-cn/library/ms164660(VS.80).aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM