Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:51:28+00:00 2026-05-31T06:51:28+00:00

in the code Configuration config = ConfigurationManager.OpenExeConfiguration (Application.ExecutablePath); ConnectionStringsSection section = config.GetSection(connectionStrings) as ConnectionStringsSection;

  • 0

in the code

Configuration config = ConfigurationManager.OpenExeConfiguration (Application.ExecutablePath);
ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection;
if (!section.SectionInformation.IsProtected)
{
    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}

I´m getting some trouble when I move the application to another machine.

is the section.SectionInformation.ProtectSection call machine dependent, meaning, I cannot copy the config file and use it on another machine ?

Is there a provider (other than DataProtectionConfigurationProvider ) that is machine independet ?

It is a requirement for my application that it works on several machines with the same config file (It must run from a flash drive).

Thanks,
Fábio

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:51:30+00:00Added an answer on May 31, 2026 at 6:51 am

    Is the section.SectionInformation.ProtectSection call machine dependent, meaning, I cannot copy the config file and use it on another machine ?

    Yes, that’s correct as far as I can tell. This article says keys are stored on a per-machine or per-user basis.

    Is there a provider (other than DataProtectionConfigurationProvider ) that is machine independet?

    Not out of the box, the two providers I know of (DataProtectionConfigurationProvider and RSAProtectedConfigurationProvider) both have the same “problem”. I found a few hints that the RSA provider allows for keys being re-used across machines, but have not found any examples on how to achieve this.

    However, there is a way to achieve what you need, I just did it myself yesterday since I had a similar problem (I had a requirement to run an app from a network location, and all clients needed to share the same encrypted config file). You can roll your own ProtectedConfigurationProvider. Here’s a few links that illustrate the concept:

    • Implementing a Protected Configuration Provider
    • How to: Build and Run the Protected Configuration Provider Example
    • Protected Configuration Provider Implementation Example

    Using these articles, I was able to build my own ProtectedConfigurationProvider that is not machine- or user-dependant and use it in an application. I have a post-build step in my release build that protects the config section and therefore I only ever deploy the protected version of it. Getting at the protected section data works as one would expect on other machines without any problems. Of course, you have to be very careful about how to encrypt and decrypt your sections safely. There’s a few examples out there outlining how to do it, this is one of them I think.

    One of the things that isn’t clearly stated in any of the three articles is how to make your app find your provider if you’re not using ASP.net. The usual way of installing it into the global assembly cache probably won’t work for you since you state you’re running an app from a flash drive. So, you’d need to add it to your app.config file instead, similar to this:

    <?xml version="1.0"?>
    <configuration>
      ... 
      <configProtectedData defaultProvider="MyEncryptionProvider">
        <providers>
          <add name="MyEncryptionProvider"
            type="MyAssembly.MyEncryptionProvider, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=whatever_the_assembly_token_is" />
        </providers>
      </configProtectedData>
      ...
    </configuration>
    

    This should work if the assembly that does the encryption is in the same path as your main assembly. I’m using a signed assembly, sn -T {Assembly} will give you the PublicKeyToken you need to enter in the config file.

    Protecting a section is then done similar to this:

    using System.Configuration;
    
    ...
    
    Configuration oConfiguration = ConfigurationManager.OpenExeConfiguration(yourExePath);
    oSection.SectionInformation.ProtectSection("MyEncryptionProvider");
    oSection.SectionInformation.ForceSave = true;
    oConfiguration.Save();
    

    I tested it today, and it worked with a config file being encrypted on a development machine (XP SP3), and being used on XP SP2, Win7 32Bit and Win7 64Bit.

    DISCLAIMER

    • Not sure if any of this works if you don’t sign your assemblies.
    • Use at your own risk, I’m not an expert on security by any standards.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code: Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationCollection settings = configuration.AppSettings.Settings; settings[IP].Value =
If I have code like this: public XALServiceConfiguration CreateInstance() { var config = ConfigurationManager.GetSection(ConfigurationSectionName)
I have the following line of code called very often: var configValue = System.Configuration.ConfigurationManager.AppSettings[ConfigValueKey];
we're configuring parts of an application at runtime: ConfigurationManager.AppSettings[someKey] = someValue; This code is
Here is my code that tries to get a custom configuration object from web.config:
I've stored configuration of my application in the app.config, by Visual Studio I've created
Every time I do a ConfigurationManager.GetSection(registeredPlugIns) for this custom section I receive this error:
I added a custom section to my app.config file for a Windows Forms Application.
I'm trying to write a very simple custom configuration section for a .NET4 application.
I have the following in my web.config: <configuration> <connectionStrings> <add name=strConDev connectionString=Data Source=dbSource;Initial Catalog=CatalogInitial;User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.