mvc4 asp.net4에서 .net4.5로 내 앱을 업데이트하고 있으며 사용자 역할이 작동하지 않습니다. 현재MVC4 .Net 4.5 사용자 역할 문제
나는 위의 도움으로 현재 사용자에게 역할을 추가하고 컨트롤러에서 사용자 역할을 확인하실 수 있습니다
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie != null)
{
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
string[] roles = authTicket.UserData.Split(new Char[] { ',' });
GenericPrincipal userPrincipal = new GenericPrincipal(new GenericIdentity(authTicket.Name), roles);
Context.User = userPrincipal;
//Or
//HttpContext.Current.User = userPrincipal;
}
}
이 코드를 사용하고 [권한 부여 (역할 = "관리자, 고객")] 또는 User.IsInRole ("관리자")
하지만 내 코드가 MVC4 ASP.Net 내가 역할 공급자를 사용하지 않으려는 4.5
에서 작동하지 않습니다. 예를 들어 Roles.CreateRole 또는 Roles.AddUserToRole
사람은 심지어 MVC 4 .NET 4.0에서 문제를 repro 수 있습니다이 감사
안녕하세요, 귀하의 도움에 감사드립니다. 예, 올바른 사용자 역할이 System.Web.Security.RolePrincipal로 대체되었으며 데이터베이스에서 역할을 얻으려고했습니다. –