Я пытаюсь проверить роль пользователя в представлении:
@if (User.IsInRole("User"))
, но получаю все время false, хотя
User.Identity.IsAuthenticated
User.Identity.Name
возвращает true и name.
Служба проверки подлинности моих форм:
public static void SignIn(string userName, string role, bool createPersistentCookie)
{
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1,
userName,
DateTime.Now,
DateTime.Now.AddMinutes(30),
createPersistentCookie,
role);
string encTicket = FormsAuthentication.Encrypt(authTicket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
{
Expires = authTicket.Expiration,
Path = FormsAuthentication.FormsCookiePath
};
if (HttpContext.Current != null)
{
HttpContext.Current.Response.Cookies.Add(cookie);
}
}
и звонки
FormsAuthenticationService.SignIn(model.UserName, "User", true);