The AudienceRestriction element specifies that the assertion is addressed to one or more
specific audiences identified by Audience elements. Although a SAML relying party that is outside the
audiences specified is capable of drawing conclusions from an assertion, the SAML asserting party
explicitly makes no representation as to accuracy or trustworthiness to such a party.
public class AudienceRestriction : Condition
Public Class AudienceRestriction
Inherits Condition
public ref class AudienceRestriction : public Condition
Shows how to create a Response object and sign it.
using System;
using ComponentPro.Saml2;
using System.Xml;
using System.Security.Cryptography.X509Certificates;
...
X509Certificate2 x509Certificate = new X509Certificate2(@"..\..\Pkey.pfx", "password");
// Create SAML Response object.
Response response = new Response();
Assertion samlAssertion = new Assertion();
Audience aud = new Audience();
aud.Uri = "http://testuri.org";
AudienceRestriction ar = new AudienceRestriction();
ar.Audiences.Add(aud);
samlAssertion.Conditions = new Conditions();
samlAssertion.Conditions.ConditionsList.Add(ar);
samlAssertion.Sign(x509Certificate);
// Add SAML Assertion
response.Assertions.Add(samlAssertion);
// You can also sign the SAML response with the following code
response.Sign(x509Certificate);
XmlElement xmlElement = response.GetXml();
System.Diagnostics.Trace.WriteLine(xmlElement.OuterXml);
Console.WriteLine(xmlElement.OuterXml);
Imports ComponentPro.Saml2
Imports System.Xml
Imports System.Security.Cryptography.X509Certificates
...
Dim x509Certificate As New X509Certificate2("..\..\Pkey.pfx", "password")
' Create SAML Response object.
Dim response As New Response()
Dim samlAssertion As New Assertion()
Dim aud As New Audience()
aud.Uri = "http://testuri.org"
Dim ar As New AudienceRestriction()
ar.Audiences.Add(aud)
samlAssertion.Conditions = New Conditions()
samlAssertion.Conditions.ConditionsList.Add(ar)
samlAssertion.Sign(x509Certificate)
' Add SAML Assertion
response.Assertions.Add(samlAssertion)
' You can also sign the SAML response with the following code
response.Sign(x509Certificate)
Dim xmlElement As XmlElement = response.GetXml()
System.Diagnostics.Trace.WriteLine(xmlElement.OuterXml)
Console.WriteLine(xmlElement.OuterXml)
ComponentPro.Saml2.ComponentPro.Saml2.AudienceRestriction