Skip to content

Instantly share code, notes, and snippets.

@shirhatti
Created February 10, 2020 16:33
Show Gist options
  • Select an option

  • Save shirhatti/b0cb69bfdbb7fd3b32c391ab7cf563f9 to your computer and use it in GitHub Desktop.

Select an option

Save shirhatti/b0cb69bfdbb7fd3b32c391ab7cf563f9 to your computer and use it in GitHub Desktop.

Revisions

  1. shirhatti created this gist Feb 10, 2020.
    25 changes: 25 additions & 0 deletions Program.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    using Microsoft.Web.Administration;

    namespace MWASample
    {
    public class Program
    {
    static void Main(string[] args)
    {
    var serverManager = new ServerManager();
    var config = serverManager.GetApplicationHostConfiguration();
    var section = config.GetSection("system.applicationHost/applicationPools");
    var collection = section.GetCollection();

    var DefaultAppPool = collection[0];
    var envVariables = DefaultAppPool.GetChildElement("environmentVariables").GetCollection();

    var newElement = envVariables.CreateElement();
    newElement.SetAttributeValue("name", "FOO");
    newElement.SetAttributeValue("value", "BAR");
    envVariables.Add(newElement);
    serverManager.CommitChanges();

    }
    }
    }