Export (0) Print
Expand All

ServiceAuthorizationManager.CheckAccess Method (OperationContext, Message)

Checks authorization for the given operation context when access to a message is required.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public virtual bool CheckAccess(
	OperationContext operationContext,
	ref Message message
)

Parameters

operationContext
Type: System.ServiceModel.OperationContext

The OperationContext.

message
Type: System.ServiceModel.Channels.Message

The Message to be examined to determine authorization.

Return Value

Type: System.Boolean
true if access is granted; otherwise; otherwise false. The default is true.

In general, applications should override CheckAccessCore instead of this method, which should only be used if the authorization decision depends on the message body. Because of performance issues, if possible you should redesign your application so that the authorization decision does not require access to the message body.

Override this method if the application associates or introduces a different set of policies for the resulting ServiceSecurityContext and Message or provide a different policy evaluation (chaining) model.

This method is responsible for calling CheckAccessCore.

The following code shows how to override this method to enforce custom access control requirements that require access to the message body.

public class myService_M_AuthorizationManager : ServiceAuthorizationManager 
{
    // set max size for message 
    int someMaxSize = 16000;
    protected override bool CheckAccessCore(OperationContext operationContext, ref Message message)
    {
        bool accessAllowed = false;
        MessageBuffer requestBuffer = message.CreateBufferedCopy(someMaxSize);

        // do access checks using the message parameter value and set accessAllowed appropriately 
        if (accessAllowed)
        {
            // replace incoming message with fresh copy since accessing the message consumes it
            message = requestBuffer.CreateMessage();
        }
        return accessAllowed;
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5 SP1, 3.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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