3

如何使用标准的 Visual Studio web.config 转换来转换 microsoft.identitymodel 配置部分中的 AudienceUris 和 federatedAuthentication 元素?

对于开发环境,我们为所有子域添加了后缀“-dev”以及特殊的 localhost 端口号,例如:realm="https://client-dev.domain.com:444"。今天主要的 web.config 反映了这一点,但理想情况下,我们希望将此设置移动到 Web.Debug.config 并且在 Web.Release.config 中,我们希望指定正确的受众和领域,没有“-dev”后缀和本地端口设置。但是,尝试将 xdt:Transform="Replace" 放在 Web.Debug.Config 内的 microsoft.identitymodel 元素中会导致以下警告:

The 'http://schemas.microsoft.com/XML-Document-Transform:transform' attribute is not declared.

当然还有运行时故障(例如,无法找到 servicecertificate)。

这是 microsoft.identitymodel 部分:

<configuration>
  <configSections>
    <section name="microsoft.identityModel" type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>

  <microsoft.identityModel>
    <service>
      <applicationService>
        <claimTypeRequired>
          <claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier" optional="false" />
          <claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" optional="false" />
        </claimTypeRequired>
      </applicationService>
      <serviceCertificate>
        <certificateReference x509FindType="FindByThumbprint" findValue="NNNNNNNNNN" storeLocation="LocalMachine" storeName="My" />
      </serviceCertificate>
      <certificateValidation certificateValidationMode="None" />
      <audienceUris>
        <add value="https://url/" />
      </audienceUris>
      <federatedAuthentication>
        <wsFederation passiveRedirectEnabled="true" issuer="https://url/" realm="https://url/" requireHttps="true" />
        <cookieHandler requireSsl="true" />
      </federatedAuthentication>
      <issuerNameRegistry type="Microsoft.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <trustedIssuers>
          <add thumbprint="NNNNNNNNNN" name="https://url/" />
        </trustedIssuers>
      </issuerNameRegistry>
    </service>
  </microsoft.identityModel>
<configuration>

现有的不起作用的解决方案:

1)这里提出了同样的问题,但没有适当的回应。RemoveAll 和 Insert 不起作用: microsoft.identityModel 上的 Web 配置转换 - 未声明“http://schemas.microsoft.com/XML-Document-Transform”属性

2)此外,尝试按照此线程上的建议操作命名空间,但这也不起作用: http ://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/9ededb66-3e34-4bba- 8e20-a2cc6025f0f9

3) configSource 看起来很有希望,但在 microsoft.identitymodel 元素中指定时再次起作用。我得到:

Warning 1   The 'configSource' attribute is not declared.

http://blog.andreloker.de/post/2008/06/16/Keep-your-config-clean-with-external-config-files.aspx

任何帮助将不胜感激!谢谢。

4

1 回答 1

1

经过大量试验和错误后,我求助于 Loren Halvorson 的 XMLPreProcess 从 TemplateWeb.config 自动生成正确的 Web.config,作为每个项目的预构建事件的一部分。

虽然我希望 Visual Studio 在这方面的尝试能够为开发人员工作,但是时间就是金钱,是我继续前进的时候了。不用说,它在 SQL Azure SDK 中也被破坏了,因为只有在发布站点时才会发生转换。在最新的 Azure SDK 中,情况不再如此,因此转换也停止工作。哦快乐!

这是一个优秀工具的链接,我认为它是每个 ASP.NET 开发人员必备的工具:

http://xmlpreprocess.codeplex.com/

于 2012-10-03T05:35:45.810 回答