Skip to content

Instantly share code, notes, and snippets.

@florisrobbemont
Created August 24, 2012 17:03
Show Gist options
  • Save florisrobbemont/3452940 to your computer and use it in GitHub Desktop.
Save florisrobbemont/3452940 to your computer and use it in GitHub Desktop.
IIS Binding from c#
// Get IIS reference (create a reference to Microsoft.Web.Administration)
ServerManager serverManager = new ServerManager();
// Create new AppPool or use existing
ApplicationPool appPool = serverManager.ApplicationPools.FirstOrDefault(x => x.Name == appPoolName);
if (appPool == null)
appPool = serverManager.ApplicationPools.Add(appPoolName);
// Umbraco is .NET 4.0
appPool.ManagedRuntimeVersion = "v4.0";
// Add site and configure
string physicalPath = System.IO.Path.Combine(siteLocation, UmbracoGenerator.Code.Constants.UmbracoRuntimeRelativePath);
serverManager.Sites.Add(appPoolName, physicalPath, 80);
serverManager.Sites[StartArguments.Name].ApplicationDefaults.ApplicationPoolName = appPoolName;
serverManager.Sites[StartArguments.Name].Bindings.Clear();
serverManager.Sites[StartArguments.Name].Bindings.Add("*:80:" + hostName, "http");
serverManager.Sites[StartArguments.Name].ServerAutoStart = true;
// Commit
serverManager.CommitChanges();
@jhonmejiasxD
Copy link

I need to assign a site created a specific user credentials, as I do it??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment