简体   繁体   中英

Encrypting connectionStrings in a web.config file

Any section in my web.config file that I want to encrypt I run this command line util: aspnet_regiis -pe "anySection" -app "/SampleApplication"

It all works just fine until I try encrypt my connectionStrings sections

I define (and I cannot change this) my connectionStrings section like this:

<connectionStrings>
    <add key="myKey" value="myValue"/>      
</connectionStrings>

But the "standard" way of defining it is like this:

  <connectionStrings>
    <add name="myName" connectionString="...." providerName="..." />
  </connectionStrings>

How when I run:

aspnet_regiis -pe "connectionStrings" -app "/SampleApplication" 

It errors with "...Unrecognized attribute 'key'....". If I change the connection string section to be the standard way it works fine. But I CANNOT use this format.

Is there a way of doing this using the aspnet_regiis util? Doing it with code is not an option for me.

Also is there a way to run this untility without specifing the application (-app "/SampleApplication") instead giving the path to the web.config file?

thanks a million

The add element inside the connectionStrings element has a well-defined schema (see http://msdn.microsoft.com/en-us/library/htw9h4z3.aspx ) and it is not the same element as the add element inside the appSettings element.

If you want to encrypt the appSettings section, and that would be the entire appSettings section, you can do this:

aspnet_regiis -pe "appSettings" -app "/SampleApplication" -prov "RsaProtectedConfigurationProvider"

It looks like you've copied and pasted an appSetting

<add key="myKey" value="myValue"/> is invalid since key and value are not an attributes the connectionString element expects.

You will have to use the "standard"

<add name="myName" connectionString="...." />


connectionStrings Element (ASP.NET Settings Schema)

我没有以管理员身份运行命令行时遇到类似的错误。

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