简体   繁体   中英

ASPNET_REGIIS encryption of connection string in web config not working after publish on IIS8

I did the encryption of connection string in web config using ASPNET_REGIIS technique. It is working fine when i run my web Api locally. When i publish it to IIS8 i get 500 internal server error. I am using entity framework for db connection. Following is my web config after encryption on server. Please help

    <?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-->

Without more details, my first thought would be that the keys have not been imported onto the destination server. You may be able to find more details on this StackOverflow question: Deploying Pre-Encrypted Configuration Files to a Production Environment .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM