다음을 통해 공유


AuthorizationResult 클래스

권한 부여 요청의 결과를 포함합니다.

네임스페이스: System.ComponentModel.DataAnnotations
어셈블리: system.servicemodel.domainservices.server.dll의 System.ServiceModel.DomainServices.Server

사용법

‘사용 방법
Dim instance As AuthorizationResult

구문

‘선언
Public NotInheritable Class AuthorizationResult
public sealed class AuthorizationResult
public ref class AuthorizationResult sealed
public final class AuthorizationResult
public final class AuthorizationResult

예제

다음 예제에서는 AuthorizationContext 값을 사용하여 인증을 사용자 지정하는 AuthorizationAttribute 구현을 보여 줍니다.

Public Class RestrictAccessToAssignedManagers
    Inherits AuthorizationAttribute

    Protected Overrides Function IsAuthorized(ByVal principal As System.Security.Principal.IPrincipal, ByVal authorizationContext As System.ComponentModel.DataAnnotations.AuthorizationContext) As System.ComponentModel.DataAnnotations.AuthorizationResult
        Dim eph As EmployeePayHistory
        Dim selectedEmployee As Employee
        Dim authenticatedUser As Employee

        eph = CType(authorizationContext.Instance, EmployeePayHistory)
            
        Using context As New AdventureWorksEntities()
            selectedEmployee = context.Employees.SingleOrDefault(Function(e) e.EmployeeID = eph.EmployeeID)
            authenticatedUser = context.Employees.SingleOrDefault(Function(e) e.LoginID = principal.Identity.Name)
        End Using

        If (selectedEmployee.ManagerID = authenticatedUser.EmployeeID) Then
            Return AuthorizationResult.Allowed
        Else
            Return New AuthorizationResult("Only the authenticated manager for the employee can add a new record.")
        End If
    End Function
End Class
public class RestrictAccessToAssignedManagers : AuthorizationAttribute
{
    protected override AuthorizationResult IsAuthorized(System.Security.Principal.IPrincipal principal, AuthorizationContext authorizationContext)
    {
        EmployeePayHistory eph = (EmployeePayHistory)authorizationContext.Instance;
        Employee selectedEmployee;
        Employee authenticatedUser;

        using (AdventureWorksEntities context = new AdventureWorksEntities())
        {
            selectedEmployee = context.Employees.SingleOrDefault(e => e.EmployeeID == eph.EmployeeID);
            authenticatedUser = context.Employees.SingleOrDefault(e => e.LoginID == principal.Identity.Name);
        }

        if (selectedEmployee.ManagerID == authenticatedUser.EmployeeID)
        {
            return AuthorizationResult.Allowed;
        }
        else
        {
            return new AuthorizationResult("Only the authenticated manager for the employee can add a new record.");
        }
    }
}

설명

Allowed 필드를 사용하여 성공적인 권한 부여 요청을 나타냅니다. null 또는 Allowed가 아닌 이 클래스의 모든 인스턴스는 거부된 권한 부여 요청을 나타냅니다.

null이 포함된 이 클래스의 인스턴스는 권한 부여 승인을 나타낼 수 있습니다. 항상 null 대신 Allowed 값을 사용해야 합니다.

상속 계층

System.Object
  System.ComponentModel.DataAnnotations.AuthorizationResult

스레드 보안

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 모든 인스턴스 멤버는 스레드로부터 안전하지 않을 수 있습니다.

플랫폼

개발 플랫폼

Windows XP Home Edition, Windows XP Professional, Windows Server 2003 , Windows Server 2008 및 Windows 2000

대상 플랫폼

Change History

참고 항목

참조

AuthorizationResult 멤버
System.ComponentModel.DataAnnotations 네임스페이스