本文整理汇总了C#中SecurityTokenHandlerCollection.CanWriteToken方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityTokenHandlerCollection.CanWriteToken方法的具体用法?C# SecurityTokenHandlerCollection.CanWriteToken怎么用?C# SecurityTokenHandlerCollection.CanWriteToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SecurityTokenHandlerCollection
的用法示例。
在下文中一共展示了SecurityTokenHandlerCollection.CanWriteToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeToken
private static string SerializeToken(SimpleWebToken accessToken, SecurityTokenHandlerCollection handlers)
{
if (handlers.CanWriteToken(accessToken))
{
string token = String.Empty;
using (var sw = new StringWriter())
{
var writer = new XmlTextWriter(sw);
handlers.WriteToken(writer, accessToken);
// remove the envelope <stringToken>
var envelope = sw.ToString();
token = XElement.Parse(envelope).Value;
}
return token;
}
return null;
}
示例2: ToTokenXmlString
/// <summary>
/// Converts a supported token to an XML string.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="handler">The token handler.</param>
/// <returns>The token XML string.</returns>
public static string ToTokenXmlString(this SecurityToken token, SecurityTokenHandlerCollection handler)
{
if (handler.CanWriteToken(token))
{
var sb = new StringBuilder(128);
handler.WriteToken(new XmlTextWriter(new StringWriter(sb)), token);
return sb.ToString();
}
else
{
throw new InvalidOperationException("Token type not suppoted");
}
}