Authorize
属性をロールで機能させるのに問題があります。これは、コントローラーをどのように装飾したかです。
[Authorize(Roles = "admin")]
public ActionResult Index()
{
...
}
これがユーザーのログイン方法です。
string roles = "admin";
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
username,
DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
roles
);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
HttpContext.Current.Response.Cookies.Add(cookie);
しかし、私のユーザーはまだアクセスを拒否されています。どこが間違っていますか?