デバッガーで User オブジェクトを掘り下げると、現在のメンバーの UserData プロパティに((System.Web.Security.FormsIdentity)(User.Identity)).Ticket.UserData
"admin" が含まれていることがわかります。
User.Identity.IsAuthenticated
動作し、User.IsInRole("admin")
false を返します。
"admin" が UserData プロパティにある場合、User.IsInRole("admin") は true を返すべきではありませんか?
アップデート
FormsAuthenticationTicket を次のように設定します。
public static string CreateEncryptedTicket(string username, string roles, DateTime expireAt, bool isPersistent = true) {
var ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, expireAt, isPersistent, roles, FormsAuthentication.FormsCookiePath);
return FormsAuthentication.Encrypt(ticket);
}
次に (ここで、roles はメンバーが属するロールのカンマ区切りのリストです):
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, MemberService.CreateEncryptedTicket(member.Id, roles, expireDate));
HttpContext.Response.Cookies.Add(cookie);