Edit

Kongsi melalui


ClaimsPrincipalPermission.CheckAccess(String, String) Method

Definition

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

public:
 static void CheckAccess(System::String ^ resource, System::String ^ action);
public static void CheckAccess (string resource, string action);
static member CheckAccess : string * string -> unit
Public Shared Sub CheckAccess (resource As String, action As String)

Parameters

resource
String

The resource on which the principal should be authorized.

action
String

The action for which the principal should be authorized.

Exceptions

The current principal is not assignable from ClaimsPrincipal.

-or-

There is no ClaimsAuthorizationManager configured.

The authorization check failed.

Examples

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");

Remarks

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.

Applies to