How to modify a key in web.config file through the code?

Anyname Donotcare

If I have in the web.config file of web application :

<appSettings>
    <add key="DD" value="567_Access"/>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>

I know how to read the data in appSettings sections like this :

 string accessD = ConfigurationManager.AppSettings["DD"];

But I want to know how to Modify (Set) the value of a key in appSettings Through the code ?

(I want through a specific check to this value to stop the application under some circumstances)

Gregor Primar
System.Configuration.ExeConfigurationFileMap configFile = new System.Configuration.ExeConfigurationFileMap();
configFile.ExeConfigFilename = "ConsoleTester.exe.config";  //name of your config file, can be from your app or external
System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(configFile, System.Configuration.ConfigurationUserLevel.None);
System.Configuration.KeyValueConfigurationCollection settings = config.AppSettings.Settings;
settings["DD"].Value = "007_Access";
config.Save();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to add custom configSections to app.config file through code

From Dev

bat file to modify web.config setting

From Dev

bat file to modify web.config setting

From Dev

Storing public key in web.config file

From Dev

How do I modify config file at runtime

From Dev

How do I move federationConfiguration out of web.config and to some custom config file and load it dynamically by code

From Dev

How to modify compatibility settings for a file through CMD?

From Dev

How to modify compatibility settings for a file through CMD?

From Dev

How to modify a .cmd file to loop through items?

From Dev

SharePoint 2010 modify web.config file with http handlers

From Dev

Modify keyboard config file

From Dev

modify KMail config file

From Dev

Modify keyboard config file

From Dev

update web.config through c# code

From Dev

update web.config through c# code

From Dev

Resolve dependency through xml file or web.config using lightinject

From Dev

How to modify RTF file with images from the code

From Dev

How to modify the following code to include file path

From Dev

ASP.Net How to limit access to a particular IP address to a particular page through web.config file (.htaccess similar)?

From Dev

ASP.Net How to limit access to a particular IP address to a particular page through web.config file (.htaccess similar)?

From Dev

How to alter CSS with web.config file

From Dev

How to add a nested Web.config file?

From Dev

How to add a nested Web.config file?

From Dev

How to get the "name" of the key combination (keybind key) for the Openbox config file

From Dev

How to get the "name" of the key combination (keybind key) for the Openbox config file

From Dev

Modify git config file globally

From Dev

Modify config file during release

From Dev

How to modify XML node value, when iterating through the file with XMLSlurper

From Dev

How to grant access to the RSA Key container while encrypting and decrypting a web.config file of an ASP.Net application

Related Related

  1. 1

    how to add custom configSections to app.config file through code

  2. 2

    bat file to modify web.config setting

  3. 3

    bat file to modify web.config setting

  4. 4

    Storing public key in web.config file

  5. 5

    How do I modify config file at runtime

  6. 6

    How do I move federationConfiguration out of web.config and to some custom config file and load it dynamically by code

  7. 7

    How to modify compatibility settings for a file through CMD?

  8. 8

    How to modify compatibility settings for a file through CMD?

  9. 9

    How to modify a .cmd file to loop through items?

  10. 10

    SharePoint 2010 modify web.config file with http handlers

  11. 11

    Modify keyboard config file

  12. 12

    modify KMail config file

  13. 13

    Modify keyboard config file

  14. 14

    update web.config through c# code

  15. 15

    update web.config through c# code

  16. 16

    Resolve dependency through xml file or web.config using lightinject

  17. 17

    How to modify RTF file with images from the code

  18. 18

    How to modify the following code to include file path

  19. 19

    ASP.Net How to limit access to a particular IP address to a particular page through web.config file (.htaccess similar)?

  20. 20

    ASP.Net How to limit access to a particular IP address to a particular page through web.config file (.htaccess similar)?

  21. 21

    How to alter CSS with web.config file

  22. 22

    How to add a nested Web.config file?

  23. 23

    How to add a nested Web.config file?

  24. 24

    How to get the "name" of the key combination (keybind key) for the Openbox config file

  25. 25

    How to get the "name" of the key combination (keybind key) for the Openbox config file

  26. 26

    Modify git config file globally

  27. 27

    Modify config file during release

  28. 28

    How to modify XML node value, when iterating through the file with XMLSlurper

  29. 29

    How to grant access to the RSA Key container while encrypting and decrypting a web.config file of an ASP.Net application

HotTag

Archive