다음을 통해 공유


AuthorizationResult.Allowed 필드

요청된 작업이 허용됨을 나타냅니다.

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

사용법

‘사용 방법
Dim value As AuthorizationResult

value = AuthorizationResult.Allowed

구문

‘선언
Public Shared ReadOnly Allowed As AuthorizationResult
public static readonly AuthorizationResult Allowed
public:
static initonly AuthorizationResult^ Allowed
public static final AuthorizationResult Allowed
public static final var Allowed : 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가 아닌 이 클래스의 모든 인스턴스는 거부된 권한 부여 요청을 나타냅니다.

플랫폼

개발 플랫폼

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

대상 플랫폼

Change History

참고 항목

참조

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