System.ComponentModel.DataAnnotations.AuthorizationAttribute에서 파생 된 사용자 지정 특성을 만들고 IsAuthorized 메서드를 재정의했습니다.AuthorizationAttribute IsAuthorized가 호출되지 않았습니다.
새 특성으로 메서드를 장식했지만 IsAuthorized 메서드가 호출되지 않습니다. 왜 그 이유를 설명 할 수 있습니까? 여기
[AttributeUsage(AttributeTargets.All)]
public class AuthorisationAttribute : System.ComponentModel.DataAnnotations.AuthorizationAttribute
{
private bool IsAuthorised { get; set; }
public AuthorisationAttribute(bool isAuthorised)
{
IsAuthorised = isAuthorised;
}
protected override AuthorizationResult IsAuthorized(IPrincipal principal, AuthorizationContext authorizationContext)
{
return IsAuthorised ? AuthorizationResult.Allowed : new AuthorizationResult("You are not authorised for this activity");
}
}
내 사용이다 : 사전에
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[Authorisation(true)]
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Pass");
}
[Authorisation(false)]
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Shouldn't see this");
}
}
덕분에
여기 내 속성 선언입니다.
내가이 게시물을 작성하기 전에 나는 꽤 많이 봤어.하지만 내 코드가 내가 예상했던대로하지 못하는 이유를 이해하는 데 도움이되는 '스티커 라벨'유추였다. 고마워. 마크. 이제 MVC를 사용하지 않거나 CAS를 사용하지 않고 문 - 사람을 구현하는 방법을 알아야합니다. 누군가 손으로 코드 샘플을 제공하면 크게 감사하게 될 것입니다. – lee