Mike Cheel
Mike Cheel

Reputation: 13106

Windows Identity Foundation - Programmatically read claim types from web.config

What is the best way to programmatically read the claim types found in the Web.config?

Upvotes: 2

Views: 721

Answers (2)

rbrayb
rbrayb

Reputation: 46700

@Andrew is correct - the list in the web.config is only used for metadata.

If you wanted to, you could Access The Claims in an ASP.NET Page, scan the web.config and compare.

Upvotes: 1

Andrew Lavers
Andrew Lavers

Reputation: 8141

I might be mistaken, but I don't think the claim types listed under applicationService/claimTypeRequested in the web.config are actually used by WIF, they're only used by FedUtil.exe when generating your application's federation metadata document. Therefore I don't think WIF exposes them anywhere under FederatedAuthentication.ServiceConfiguration like one might expect.

You can always just crack open the web.config and scan for them yourself, like so:

XmlDocument doc = new XmlDocument();
doc.Load(WebConfigurationManager.OpenWebConfiguration("~").FilePath);
XmlNamespaceManager docNs = new XmlNamespaceManager(doc.NameTable);
docNs.AddNamespace("fed", doc.DocumentElement.NamespaceURI);
XmlNodeList claimsNodes = doc.SelectNodes(@"/fed:configuration/fed:microsoft.identityModel/fed:service[count(@name)=0 or @name='']/fed:applicationService/fed:claimTypeRequired/fed:claimType", docNs);

Upvotes: 3

Related Questions