ClaimsPrincipalPermission::CheckAccess Method (String^, String^)
Checks if the current principal is authorized to perform the specified action on the specified resource.
Assembly: System.IdentityModel.Services (in System.IdentityModel.Services.dll)
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.
| Exception | Condition |
|---|---|
| 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");
Available since 4.5