역할을 유지하려고하고 권한 기반 인증을 얻으려고합니다. ASP.Net MVC : 사용자 역할이 제공된 역할과 대조되는 위치
그냥 http://www.dotnetcurry.com/aspnet-mvc/1102/aspnet-mvc-role-based-security는 사용자 로그인을 가정하고 그 판매 역할을하지만 행동 자신이 관리 역할에 대한 액세스를 시도하지만 난 사용자 역할 및 공급 역할이 사용자를 알고 비교하는 어떤 코드를 발견이 기사를 읽는 것은 관리자 역할을 아닙니다. 이 지역은
private void IsUserAuthorized(AuthorizationContext filterContext)
{
// If the Result returns null then the user is Authorized
if (filterContext.Result == null)
return;
//If the user is Un-Authorized then Navigate to Auth Failed View
if (filterContext.HttpContext.User.Identity.IsAuthenticated)
{
// var result = new ViewResult { ViewName = View };
var vr = new ViewResult();
vr.ViewName = View;
ViewDataDictionary dict = new ViewDataDictionary();
dict.Add("Message", "Sorry you are not Authorized to Perform this Action");
vr.ViewData = dict;
var result = vr;
filterContext.Result = result;
}
}
[AuthLog(Roles = "Manager")]
public ActionResult Create()
{
var Product = new ProductMaster();
return View(Product);
}
[AuthLog(Roles = "Sales Executive")]
public ActionResult SaleProduct()
{
ViewBag.Message = "This View is designed for the Sales Executive to Sale Product.";
return View();
}
이 역할 "판매 집행"과 사용자 1이 코드에서 USER1 어떤 역할 호출하지 않았다 관리자 비교입니다 다음 행동 만들기에 액세스하려고 가정
참조? 어떻게 된 일입니까? 누가 커튼 뒤에서 일을하고 있니?사용자 1은 관리자 역할을 가지고 있지 않습니까? 인 코드로이 확인이 수행 된 경우에만이 점에 유의하시기 바랍니다.
감사
자신의AuthLogAttribute
이
OnAuthorization
에 다음
AuthorizeAttribute
에서 inhereting 것을
죄송합니다. 시스템 1이 시스템 1을 감지하는 방법이 관리자라는 역할을 가지고 있는지 여부는 아직 명확하지 않습니다. user1에 manager라는 역할이없는 경우 오류 페이지로 리디렉션합니다. 가능한 경우 작은 작업 코드를 게시하십시오. –
AuthorizeAttribute의 소스 코드를 살펴보십시오. 특히 102 행 : https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/System.Web.Http/AuthorizeAttribute.cs#L102 사용자가 속성에 전달 된 역할은 –
링크에 감사하지만 아래 라인은 명확하지 않습니다. if (_usersSplit.Length> 0 &&! _usersSplit.Contains (user.Identity.Name, StringComparer.OrdinalIgnoreCase)) { false false; } if (_rolesSplit.Length> 0 &&! _rolesSplit.Any (user.IsInRole)) { false false; }'이해하도록 도와주세요. –