{"id":16,"date":"2007-08-12T21:03:00","date_gmt":"2007-08-13T02:03:00","guid":{"rendered":"http:\/\/blogs.devhorizon.com\/reza\/?p=16"},"modified":"2007-12-26T17:46:59","modified_gmt":"2007-12-26T22:46:59","slug":"adding-and-removing-keys-from-appsettings-in-webconfig","status":"publish","type":"post","link":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/","title":{"rendered":"Adding and Removing keys from appSettings in web.config"},"content":{"rendered":"<p>Today, I was struggling with adding and removing entries from web.config\/appsettings in my feature receiver class. Well, it was quite easy to add , but removing was giving me a real hard time. I used my <a href=\"http:\/\/www.google.ca\/\">perfect indexing tool <\/a>and I came across these great posts from <a href=\"http:\/\/daniellarson.spaces.live.com\/blog\/cns!D3543C5837291E93!954.entry\">Daniel Larson<\/a>  and <a href=\"http:\/\/sharepointsolutions.blogspot.com\/2006\/12\/using-spwebconfigmodificat_116736917110571614.html\">Tony Bierman<\/a>. By first look at their posts I realized that removing requires a *right* call to SPWebConfigModification constructor, otherwise it won&#8217;t ever happen. Both posts are for adding Ajax http handlers, but one can easily alter them to make the solution work for appsettings as well.<\/p>\n<blockquote><p>protected void ModifyWebApplication(SPWebApplication app, bool removeModification)<br \/>\n {<\/p>\n<p> SPWebConfigModification modification = new SPWebConfigModification(&#8220;add[@key=&#8217;TotalDigits&#8217;]&#8221;, &#8220;configuration\/appSettings&#8221;);<br \/>\n modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode ;<br \/>\n modification.Value = <span>&#8220;&lt;add key=\\&#8221;TotalDigits\\&#8221; value=\\&#8221;21\\&#8221; \/&gt;&#8221;;<\/span><br \/>\n modification.Sequence = 0;<br \/>\n if (removeModification)<br \/>\n app.WebConfigModifications.Remove(modification);<br \/>\n else<br \/>\n app.WebConfigModifications.Add(modification);<br \/>\n SPFarm.Local.Services.GetValue().ApplyWebConfigModifications();<\/p>\n<p> }<\/p><\/blockquote>\n<p> <o:p><\/o:p>As Daniel has mentioned in his comments, a real benefit of using the SPWebApplication in your code is that the changes are applied to the farm, since the SPWebApplication represents that virtual web application that lives in the farm context.Thanks Daniel and Tony!<img loading=\"lazy\" decoding=\"async\" src=\"\/\/blogs.devhorizon.com\/aggbug.aspx?PostID=492\" height=\"1\" width=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, I was struggling with adding and removing entries from web.config\/appsettings in my feature receiver class. Well, it was quite easy to add , but removing was giving me a real hard time. I used my perfect indexing tool and I came across these great posts from Daniel Larson and Tony Bierman. By first look [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[3],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-moss-2007","tag-moss-2007"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Adding and Removing keys from appSettings in web.config - Reza Alirezaei&#039;s Blog %<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Reza Alirezaei\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2007\\\/08\\\/12\\\/adding-and-removing-keys-from-appsettings-in-webconfig\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2007\\\/08\\\/12\\\/adding-and-removing-keys-from-appsettings-in-webconfig\\\/\"},\"author\":{\"name\":\"Reza Alirezaei\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#\\\/schema\\\/person\\\/cdbb24d283697a65951cb4a14e474938\"},\"headline\":\"Adding and Removing keys from appSettings in web.config\",\"datePublished\":\"2007-08-13T02:03:00+00:00\",\"dateModified\":\"2007-12-26T22:46:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2007\\\/08\\\/12\\\/adding-and-removing-keys-from-appsettings-in-webconfig\\\/\"},\"wordCount\":199,\"commentCount\":0,\"keywords\":[\"MOSS 2007\"],\"articleSection\":[\"MOSS 2007\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2007\\\/08\\\/12\\\/adding-and-removing-keys-from-appsettings-in-webconfig\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2007\\\/08\\\/12\\\/adding-and-removing-keys-from-appsettings-in-webconfig\\\/\",\"url\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2007\\\/08\\\/12\\\/adding-and-removing-keys-from-appsettings-in-webconfig\\\/\",\"name\":\"Adding and Removing keys from appSettings in web.config - Reza Alirezaei's Blog %\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#website\"},\"datePublished\":\"2007-08-13T02:03:00+00:00\",\"dateModified\":\"2007-12-26T22:46:59+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#\\\/schema\\\/person\\\/cdbb24d283697a65951cb4a14e474938\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/2007\\\/08\\\/12\\\/adding-and-removing-keys-from-appsettings-in-webconfig\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#website\",\"url\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/\",\"name\":\"Reza Alirezaei's Blog\",\"description\":\"Blogging from the field!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/#\\\/schema\\\/person\\\/cdbb24d283697a65951cb4a14e474938\",\"name\":\"Reza Alirezaei\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g\",\"caption\":\"Reza Alirezaei\"},\"url\":\"https:\\\/\\\/blogs.devhorizon.com\\\/reza\\\/author\\\/rezaa\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding and Removing keys from appSettings in web.config - Reza Alirezaei's Blog %","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/","twitter_misc":{"Written by":"Reza Alirezaei","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/#article","isPartOf":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/"},"author":{"name":"Reza Alirezaei","@id":"https:\/\/blogs.devhorizon.com\/reza\/#\/schema\/person\/cdbb24d283697a65951cb4a14e474938"},"headline":"Adding and Removing keys from appSettings in web.config","datePublished":"2007-08-13T02:03:00+00:00","dateModified":"2007-12-26T22:46:59+00:00","mainEntityOfPage":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/"},"wordCount":199,"commentCount":0,"keywords":["MOSS 2007"],"articleSection":["MOSS 2007"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/","url":"https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/","name":"Adding and Removing keys from appSettings in web.config - Reza Alirezaei's Blog %","isPartOf":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/#website"},"datePublished":"2007-08-13T02:03:00+00:00","dateModified":"2007-12-26T22:46:59+00:00","author":{"@id":"https:\/\/blogs.devhorizon.com\/reza\/#\/schema\/person\/cdbb24d283697a65951cb4a14e474938"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blogs.devhorizon.com\/reza\/2007\/08\/12\/adding-and-removing-keys-from-appsettings-in-webconfig\/"]}]},{"@type":"WebSite","@id":"https:\/\/blogs.devhorizon.com\/reza\/#website","url":"https:\/\/blogs.devhorizon.com\/reza\/","name":"Reza Alirezaei's Blog","description":"Blogging from the field!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blogs.devhorizon.com\/reza\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blogs.devhorizon.com\/reza\/#\/schema\/person\/cdbb24d283697a65951cb4a14e474938","name":"Reza Alirezaei","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3ba940d84e0ecb909e62e93df4c56daf0395c7e53c914467ab2ee73124a7d7b6?s=96&d=mm&r=g","caption":"Reza Alirezaei"},"url":"https:\/\/blogs.devhorizon.com\/reza\/author\/rezaa\/"}]}},"_links":{"self":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.devhorizon.com\/reza\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}