Question

How do i configure dynamic federation metadata generator http handler that comes with StarterSTS to work along with ASP.NET MVC 4, right now i got this configuration inside web.config on IIS 7 but browser returns 404 not found

<!-- handler to dynamically generate WS-Federation metadata -->
<location path="FederationMetadata/2007-06">
    <system.webServer>
        <handlers>
            <add name="MetadataGenerator" path="FederationMetadata.xml" verb="GET" type="Thinktecture.IdentityServer.WSFedMetadataGenerator,Thinktecture" />
        </handlers>
    </system.webServer>
    <system.web>
        <httpHandlers>
            <add path="FederationMetadata.xml" verb="GET" type="Thinktecture.IdentityServer.WSFedMetadataGenerator,Thinktecture" />
        </httpHandlers>
    </system.web>
</location>

404 Not found

https://localhost/website/FederationMetadata/2007-06/

Was it helpful?

Solution

Ok here is the truth it does not work. So here is what i did,

  • created a new asp.net mvc controller named it FederationMetadata

  • Copied the code to generate the federation metadata in the Index action method

  • Always point to https://<pc:name>/stsvirtualdirectoryname/FederationMetadata/ to get the federation metadata xml document

Code

        if (STS.Configuration.Endpoints.WSFedMex)
        {
            EnsureInitialized();
            var serializer = new MetadataSerializer();
            var sb = new StringBuilder(512);
            serializer.WriteMetadata(XmlWriter.Create(new StringWriter(sb),new XmlWriterSettings { OmitXmlDeclaration = true }), _entity);
            return new ContentResult(){Content = sb.ToString(),ContentEncoding = Encoding.UTF8,ContentType = "text/xml"};
        }
        else
        {
            throw new HttpException(404, "Not found");
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top