ASP.NET アプリケーションに役割があります。私は問題を理解しました(私は思う)。アプリケーション内のすべてのページがロールとパーミッションを使用する問題。したがって、ページの読み込みで次の関数を使用します
if (Roles.IsUserInRole("Admin")) { // ページを表示する } else { // いいえ }
この質問から私の問題の解決策を見つけましたWindowsTokenRoleProviderでパフォーマンスが悪い
しかし、いくつかの違いがあります 1.上記の質問ではWindowsTokenRoleProviderを使用しています。私は SqlRoleProvider を使用しています
上記の問題のため、上記の解決策は私にはうまくいきません。
私がこれまでに行ったこと、そして部分的に成功したことは、SqlRoleProvider からクラスを派生させ、上記の質問と同じであるが変更されたこの関数を含めたことです。このようになるようにweb.configを変更しました
<roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPR0L3S" cookieTimeout="117" cookieSlidingExpiration="true" cookieProtection="All" createPersistentCookie="false" defaultProvider="CustomSqlRoleProvider">
<providers>
<add name="CustomizedRoleProvider" type="CustomSqlRoleProvider" connectionStringName="PEGConn" applicationName="/CRM"/>
</providers>
</roleManager>
これは私のクラス内の関数であり、取得します(ユーザーがログインしたときにのみ実行されます)
public override string[] GetRolesForUser(string username)
{
// Will contain the list of roles that the user is a member of
List<string> roles = null;
// Create unique cache key for the user
string key = String.Concat(username, ":", base.ApplicationName);
// Get cache for current session
Cache cache = HttpContext.Current.Cache;
// Obtain cached roles for the user
if (cache[key] != null)
{
roles = new List<string>(cache[key] as string[]);
}
// Was the list of roles for the user in the cache?
if (roles == null)
{
string[] AllRoles = GetAllRoles();
roles = new List<string>();
// For each system role, determine if the user is a member of that role
foreach (String role in AllRoles)
{
if (base.IsUserInRole(username, role))
{
roles.Add(role);
}
}
// Cache the roles for 1 hour
cache.Insert(key, roles.ToArray(), null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration);
}
// Return list of roles for the user
return roles.ToArray();
}
問題は、 Roles.IsUserInRole 関数が同じ古いものを呼び出すときです
System.Web.Security.Roles.IsUserInRole
関数。新しいクラスでこの関数をオーバーロードしましたが、実行されません。私は基本的にすべてのロールをキャッシュしているので、ページが更新されるたびに、アプリケーションは最初からすべてのロールを検索しません。
から別のクラスを派生させる必要がありSystem.Web.Security.Roles.IsUserInRole
ますか? やった人いる?
各ページは、フレッシュで長すぎる約4〜8秒かかります. コードは VS 2008、C# 3.5 にあります