Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从SAML标记读取SAML属性_C#_Wcf_Saml - Fatal编程技术网

C# 从SAML标记读取SAML属性

C# 从SAML标记读取SAML属性,c#,wcf,saml,C#,Wcf,Saml,我正在从XML文件加载SAML令牌 string certificatePath = @"D:\Projects\SAMLDemo\Server.pfx"; X509Certificate2 cert = new X509Certificate2(certificatePath, "shani"); string samlFilePath = @"D:\Projects\SAMLDemo\saml.xml"; XmlReader reader = XmlReader.Create(samlFi

我正在从XML文件加载SAML令牌

string certificatePath = @"D:\Projects\SAMLDemo\Server.pfx";
X509Certificate2 cert = new X509Certificate2(certificatePath, "shani");

string samlFilePath = @"D:\Projects\SAMLDemo\saml.xml";
XmlReader reader = XmlReader.Create(samlFilePath);

List<SecurityToken> tokens = new List<SecurityToken>();
tokens.Add(new X509SecurityToken(cert));

SecurityTokenResolver outOfBandTokenResolver = SecurityTokenResolver.CreateDefaultSecurityTokenResolver(new ReadOnlyCollection<SecurityToken>(tokens), true);
SecurityToken securityToken = WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, outOfBandTokenResolver);

SamlSecurityToken deserializedSaml = securityToken as SamlSecurityToken;
stringcertificatePath=@“D:\Projects\SAMLDemo\Server.pfx”;
X509Certificate2 cert=新X509Certificate2(certificatePath,“shani”);
字符串samlFilePath=@“D:\Projects\SAMLDemo\saml.xml”;
XmlReader=XmlReader.Create(samlFilePath);
列表标记=新列表();
添加(新的X509SecurityToken(证书));
SecurityTokenResolver outOfBandTokenResolver=SecurityTokenResolver.CreateDefaultSecurityTokenResolver(新的只读集合(令牌),true);
SecurityToken SecurityToken=WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader,outOfBandTokenResolver);
SamlSecurityToken反序列化DSAML=作为SamlSecurityToken的securityToken;
如何从反序列化的DSAML读取SAML属性

我需要属性的字符串值

这不管用吗

foreach (SamlStatement statement in deserializedSaml.Assertion.Statements)
{
  SamlAttributeStatement attributeStatement = statement as SamlAttributeStatement;
  if (null != attributeStatement)
  {
    foreach (SamlAttribute attribute in attributeStatement.Attributes)
    {
      DoWhateverYouLikeWith(attribute);
    }
  }
}

真的没有必要在主题行中添加“C#”,因为您已经在标记中添加了它。这是SAML 1还是SAML 2?
System.IdentityModel
类文档似乎引用的是SAML 1.1而不是2。啊,现在我看到.net 4.5的类名为
Saml2XXX
,例如
Saml2Assertion