Question

I have an ASP.NET MVC application that uses WIF to set up federated authentication, if I set the audience uris in the web.config like so:

<system.identityModel>
  <identityConfiguration>
    <audienceUris>
      <add value="https://foo.org/" />
      <add value="https://bar.com/"/>
    </audienceUris>
    <!-- more setup -->
  </identityConfiguration>
</system.identityModel>

everything works. But I would like to add additional audience uris in my C# code.

Question

How do I get hold of the AudienceUriElementCollection used by WIF?

How do I add new audience uris to it and have WIF use the new ones too?

Était-ce utile?

La solution 2

You can subscribe to the ServiceConfigurationCreated event (off FederatedAuthentication) in Application_Start. From there you have programmatic access to configuration.

Autres conseils

This is code i recently tried (only tested in development).

Uri uri = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host);

 if(!FederatedAuthentication.ServiceConfiguration.AudienceRestriction.AllowedAudienceUris.Contains(uri))
             FederatedAuthentication.ServiceConfiguration.AudienceRestriction.AllowedAudienceUris.Add(uri);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top