How to encrypt applicationSettings (not appSettings) in web.config -
09-13-2007
, 03:04 AM
I’m trying to encrypt a applicationSettings-section in web.config using the
aspnet_regiis.exe command along the lines of the article “How To: Encrypt
Configuration Sections in ASP.NET 2.0 Using DPAPI”. I have no problems
encrypting sections like the connectionStrings- or the appSettings-sections,
but encrypting my applicationSettings-section gives me a lot of trouble:
The command aspnet_regiis.exe accidentally removes(!?) the
configSections-section of my web.config while encrypting the
applicationSettings-section, and if I manually re-enter the
configSections-section, ASP.NET gives the following parser Error Message:
The attribute 'configProtectionProvider' cannot be specified because its
name starts with the reserved prefix 'config' or 'lock'.
Is this a bug of aspnet_regiis.exe, or am I just doing something terribly
wrong?
To reproduce my problem, please follow the description below:
Make a .NET 2.0 class library assembly for use from a web application. Add a
Settings.settings file in the class library project to configure your
server-assembly in a type safe manner. To configure the server from your
client web.config, add the apropriate sections: configSections and
applicationSettings, like this:
<?xml version="1.0"?>
<configuration>
<connectionStrings/>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Settings>
<setting name="Setting1" serializeAs="String">
<value>Hello</value>
</setting>
<setting name="Setting2" serializeAs="String">
<value>World</value>
</setting>
</Settings>
</applicationSettings>
<appSettings/>
<system.web/>
</configuration>
Now try to save the web.config in say c:\ and run the command:
aspnet_regiis.exe -pef "applicationSettings" C:\
to encrypt the applicationSettings section. Note that the
connectionStrings-section has to be at the top of the configuration-section
for aspnet_regiis.exe to see the applicationSettings section!?
The applicationSettings-section is now encrypted but configSections-section
has now disappeared from the web.config. The missing configSections-section
means that the applicationSettings-section will no longer be recognized by
ASP.NET as a valid a configuration section.
Adding the configSections-section again manually, results in the following
ASP.NET error:
Parser Error Message: The attribute 'configProtectionProvider' cannot be
specified because its name starts with the reserved prefix 'config' or 'lock'.
Hope someone will help me out.
Best regrads,
Michael Brandt Lassen
3F, Denmark |