在自定義角色提供.NET 2.0中(從RoleProvider繼承),該方法的isUserInRole已硬編碼爲總是返回true:Roles.IsUserInRole在以下簡單場景中的行爲與預期相符嗎?
public override bool IsUserInRole(string username, string roleName) { return true; }
在配置爲使用該角色提供一個ASP.NET應用程序,以下代碼返回true(如預期):
Roles.IsUserInRole("any username", "any rolename"); // results in true
但是,下面的代碼返回false:
Roles.IsUserInRole("any rolename"); // results in false
ñ注意User.IsInRole(「任何角色名稱」)也返回false。
- 這是預期的行爲?
- 假設僅使用角色名稱的重載仍然會調用重寫的IsUserInRole,這是不正確的嗎?
更新:請注意,似乎沒有可用於接受單個字符串,這導致了我在#2假設的版本重寫。
非常感謝!我現在已經下載了Reflector工具,謝謝你指點我。你對用戶名是空白是正確的,我使用匿名身份驗證,導致身份是System.Security.Principal.GenericIdentity,恰好有一個空白的Name屬性。 – 2008-12-12 16:41:27