Export (0) Print
Expand All

ClaimsPrincipalPermission.CheckAccess Method

.NET Framework 4.5

Checks if the current principal is authorized to perform the specified action on the specified resource.

Namespace:  System.IdentityModel.Services
Assembly:  System.IdentityModel.Services (in System.IdentityModel.Services.dll)

public static void CheckAccess(
	string resource,
	string action
)

Parameters

resource
Type: System.String

The resource on which the principal should be authorized.

action
Type: System.String

The action for which the principal should be authorized.

ExceptionCondition
InvalidOperationException

The current principal is not assignable from ClaimsPrincipal.

-or-

There is no ClaimsAuthorizationManager configured.

SecurityException

The authorization check failed.

The principal must be authorized for the specified action on the specified resource or the SecurityException exception is thrown.

The ClaimsAuthorizationManager.CheckAccess method of the configured claims authorization manager is invoked with an AuthorizationContext composed of the active principal (CurrentPrincipal), the resource, and the action.

The following example shows how to protect a resource by using the CheckAccess method. The configured claims authorization manager is invoked to evaluate the current principal against the specified resource and action. If the current principal is not authorized for the specified action on the specified resource, a SecurityException is thrown; otherwise, execution proceeds.

// 
// Method 1. Simple access check using static method.  
// Expect this to be most common method. 
//
ClaimsPrincipalPermission.CheckAccess("resource", "action");

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft