ロールまたはユーザー名を取得するために内部で Web サービス メソッドを使用するカスタム ロール プロバイダーを作成しました。このプロバイダーはSystem.Web.Security.RoleProviderから継承します。web.configファイルで、Cookie を使用する .NET 提供のキャッシュ機能を有効にしました。
このプロバイダーの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");
}
このコードを (テスト Web サイトから) デバッグしている間、メソッドの誘導が冗長であるかどうかに関係なく、デバッガーはプロバイダーに示されている各メソッドを入力し、内部のすべてのロジックを実行します。各メソッドの 2 番目の呼び出しは、キャッシュからプロバイダーに直接要求せずに結果が返されるため、実行されるべきではないと考えました。
私がしていること/考えが間違っていること、およびキャッシュ機能を修正する方法は?
よろしく