2013-02-15 3 views
1

I already asked 비슷한 질문이 있지만 솔루션을 단순화 할 수 있는지 궁금합니다. 이미 알 수 있듯이 로그 된 사용자가 자신의 데이터에만 액세스 할 수 있도록하고 싶습니다. mvc3에서 사용자 지정 멤버 자격 공급자를 사용하고 있습니다.기록 된 사용자가 자신의 데이터에만 액세스 할 수 있도록하십시오.

[Authorize(Users=httpContext.User.Identity.Name)] 
public ActionResult UserArea() 
{} 

감사

답변

0

가 새로운 속성을 확인하고 AuthorizeCore 방법 오버라이드 (override) : 컨트롤러에서 다음

public class CustomAuthorizeAttribute : AuthorizeAttribute 
{ 
    protected override bool AuthorizeCore(HttpContext.User user) 
    { 
    // Generally authenticated to the site 
    if (!httpContext.User.Identity.IsAuthenticated) { 
     return false; 
    } 

    return true; 
    } 
} 

을 수행

[CustomAuthorize(httpContext.User] 
public ActionResult MyControllerAction() 
{ 
    return View(); 
} 

http://code.commongroove.com/2012/04/20/asp-net-mvc-simple-custom-authorization-by-inheriting-from-the-authorizeattribute/

관련 문제