首页 > 解决方案 > 在 IIS8 上发布后,Web 配置中连接字符串的 ASPNET_REGIIS 加密不起作用

问题描述

我使用 ASPNET_REGIIS 技术对 Web 配置中的连接字符串进行了加密。当我在本地运行我的 Web Api 时它工作正常。当我将它发布到 IIS8 时,我收到 500 内部服务器错误。我正在使用实体框架进行数据库连接。以下是我在服务器上加密后的网络配置。请帮忙

    <?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=301879
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings></appSettings>
  <system.web>
    <compilation targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" />
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
  <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
          <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <KeyName>Rsa Key</KeyName>
          </KeyInfo>
          <CipherData>
            <CipherValue>b5kY1n7Zp1P1FEEDi5nYlM0rdtU6gtpKm0AfudUqsCeF7Hzc6Q93SbXlwX06tfVMWK/HntfqJ28Y6DgRJth/PIewupMsETLF/tnHHyuHWuHetiup1P5e0q24WyqlrsaNWD6NYzl+XYW6C6lNuun3UXkp+B6UJPl+553tUq5TKeQ=</CipherValue>
          </CipherData>
        </EncryptedKey>
      </KeyInfo>
      <CipherData>
        <CipherValue>QhdAFCWmfEVRrsQrfwpFDgWyLQa2Oymicsf5Hp3BDgELJUjAeUOfBzSp2x20gEClqPNkBXQhkCgJht5ZmzqavxHjDTVVClzPQRNjcI6Rec1D6NDwkfCbY2zPU7150cX9AC0J48bwblOc7DuxSR6+A97D0SSWmFaexYMQZxsfq4fMcRGTKUrKL83bXELP0rUo14U22J1dpnRwQiS2Lu0ctR1OjvLVD+YKt3R7mpkPHJPOcikOeL65P4dy2UZwj8EBWzgSrEDLvYqVk5H7BGP4KxpL+mX4krUTQqlDmriUZ4Q3+YmpfVHVAsx9XcudA6PaFjlFTfkBL5RTKMv/EYeITLApfIRnPSWla38NGqC5pMV76df7DQXWoSb+22vTjyCAvQlpApDwKR0tATdDJagwZcXSeE/82VHYOqyFVSY9gZkTsauXSYOW4eQPb1yhgp1jwWAVmKNU6qCgKbJUCE8FlxOUrQ1AjOsLBZthzogaTZQRLdnzX1vBRl0vv+E6uvBAwujHGeC9Dh6skbckVD8vAqG6hRXvBV0y17egjmAS0miLKpHzt0TV74UD1aRiqEt/zRRhYPMBCMs1NJ2vtMpDk1stJqnAfj8IEhAQ+GAFLxhV9eXvXg8zE3s309mG738btGircXn9ErgdABi8qF/YU4U7yklA/xF6STVN8wlij2AUO+k38L9H1/AFgAOYSBh6RQkEIXFlhhrIMtiJQOUIpmKrs4qrIzVWnp9Usz3bnNoO3XkwclzATZv+9OSHg3uLnRUbhire61o9l3hDJzD+MijZ3dD28g579BCymzF3XFO/92Y7gWaXn/nOAzplluUj0gsGvNlAebephxS0PovMENGtGCLsWI5qRR0qri46AiEq3i549LN/PaLH9cU/LL0uAXI5UXjrqZbPPmCo4eIYbkHp3vPE/BJHXfD4sPqIoxeuqJ4MYLWcJ6Z7i++n5tXj2svLaPU8GlV8/9tkYtevRs1a3KsMNu2Owmz7dLEUrXGsB3zxIj7Al7aaWfTKA8um+NAfzlZMuQjADv4XZX1RIn120Fp5PEpueK409ej2YI75B9Ob6Btu4srsM55QzkRwOldSeJToS8Z5P2/22FXu75TnKM+olLJCu/SeyxmE1vxntSkpGlFRxCQOvMTdjndLJM3pStY8jtY=</CipherValue>
      </CipherData>
    </EncryptedData>
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
<!--ProjectGuid: 866D7495-35B3-4EE8-9806-8A547E5AA3D2-->

标签: c#asp.net-mvcasp.net-web-api

解决方案


如果没有更多细节,我的第一个想法是密钥尚未导入目标服务器。您可以找到有关此 StackOverflow 问题的更多详细信息:将 预加密的配置文件部署到生产环境


推荐阅读