4
MVC 3 프로젝트가 있고 AD를 사용하여 사용자를 인증합니다. "Admin"역할의 사용자 만 액세스 할 수있는 페이지가 있습니다.MVC3에서 페이지 권한이 없을 때 사용자 리디렉션
나는 로그인을 만들어 사용자를 승인하므로 관리자 만 사이트의 관리자 부분에 액세스 할 수 있습니다. 내가 가진 문제는 사용자가 관리자가 아닌데 좋은 오류 메시지를 표시 할 수없는 것 같습니다. 여기
내 actionFilterattributepublic class AdminOnlyAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
bool isAuthorised = false;
IPrincipal user = filterContext.HttpContext.User;
if (user.Identity.IsAuthenticated)
{
if (user.IsInRole("Admin"))
{
isAuthorised = true;
}
}
if (!isAuthorised)
{
//error message here
}
}
입니다 그리고 이것은 어떤 도움에 감사드립니다 관리자
[AdminOnly]
public ActionResult Index()
{
//admin stuff
}
내 컨트롤러, 사전에 감사