asp.net mvc 4的StarterSTS FederationMetadata Generator配置

时间:2012-12-27 06:36:26

标签: asp.net-mvc-4 web-config single-sign-on federation

如何配置StarterSTS附带的动态联合元数据生成器http处理程序与ASP.NET MVC 4一起使用,现在我在IIS 7上的web.config中获得了此配置,但浏览器返回404未找到

<!-- 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未找到

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

1 个答案:

答案 0 :(得分:0)

好的,这是事实,它不起作用。所以这就是我所做的,

  • 创建了一个名为FederationMetadata的新asp.net mvc控制器

  • 复制代码以在“索引”操作方法

  • 中生成联合元数据
  • 始终指向https://<pc:name>/stsvirtualdirectoryname/FederationMetadata/以获取联合元数据xml文档

代码

        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");
        }