Szerkesztés

Megosztás a következőn keresztül:


SecurityTokenHandler.CanReadToken Method

Definition

Returns a value that indicates whether the specified token can be deserialized as a token of the type processed by this instance.

Overloads

CanReadToken(String)

Returns a value that indicates whether the specified string can be deserialized as a token of the type processed by this instance.

CanReadToken(XmlReader)

Returns a value that indicates whether the XML element referenced by the specified XML reader can be read as a token of the type processed by this instance.

CanReadToken(String)

Returns a value that indicates whether the specified string can be deserialized as a token of the type processed by this instance.

public:
 virtual bool CanReadToken(System::String ^ tokenString);
public virtual bool CanReadToken (string tokenString);
abstract member CanReadToken : string -> bool
override this.CanReadToken : string -> bool
Public Overridable Function CanReadToken (tokenString As String) As Boolean

Parameters

tokenString
String

The token string to read.

Returns

true if the ReadToken(String) method can read the element; otherwise, false. The default is false.

Remarks

The default implementation always returns false.

If you override this method, you must also override the SecurityTokenHandler.ReadToken method to provide the logic to deserialize the token.

Applies to

CanReadToken(XmlReader)

Returns a value that indicates whether the XML element referenced by the specified XML reader can be read as a token of the type processed by this instance.

public:
 virtual bool CanReadToken(System::Xml::XmlReader ^ reader);
public virtual bool CanReadToken (System.Xml.XmlReader reader);
abstract member CanReadToken : System.Xml.XmlReader -> bool
override this.CanReadToken : System.Xml.XmlReader -> bool
Public Overridable Function CanReadToken (reader As XmlReader) As Boolean

Parameters

reader
XmlReader

An XML reader positioned at a start element. The reader should not be advanced by this method.

Returns

true if the ReadToken(XmlReader) method can read the element; otherwise, false. The default is false.

Examples

The following code shows how to override the CanReadToken method to determine whether a token can be read by a handler. The code is taken from the Custom Token sample. This sample provides custom classes that enable processing of Simple Web Tokens (SWT). For information about this sample and other samples available for WIF and where to download them, see WIF Code Sample Index.

/// <summary>
/// Indicates whether the current XML element can be read as a token of the type handled by this instance.
/// </summary>
/// <param name="reader">An XML reader positioned at a start element. The reader should not be advanced.</param>
/// <returns>True if the ReadToken method can the element.</returns>
public override bool CanReadToken( XmlReader reader )
{
    bool canRead = false;

    if ( reader != null )
    {
        if ( reader.IsStartElement( BinarySecurityToken)
            && ( reader.GetAttribute( ValueType ) == SimpleWebTokenConstants.ValueTypeUri ) )
        {
            canRead = true;
        }
    }

    return canRead;
}

Remarks

The default implementation always returns false.

A derived class checks the element that the reader is referring to in order to determine whether the instance can deserialize a security token. This is typically accomplished through a call to the IsStartElement method with the appropriate element and namespace strings specified. If you override CanReadKeyIdentifierClause, you must also override the SecurityTokenHandler.ReadToken method or the SecurityTokenHandler.ReadToken method to provide the logic to deserialize the key identifier clause.

Applies to