Created
February 10, 2020 16:33
-
-
Save shirhatti/b0cb69bfdbb7fd3b32c391ab7cf563f9 to your computer and use it in GitHub Desktop.
MWA Set environment variable on ApplicationPool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment