Skip to content

Instantly share code, notes, and snippets.

@CharlTruter
Created March 19, 2012 11:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharlTruter/2107864 to your computer and use it in GitHub Desktop.
Save CharlTruter/2107864 to your computer and use it in GitHub Desktop.
Stopping a site in IIS using Microsoft.Web.Administration in C#
void StopSite(string siteName)
{
using (ServerManager manager = new ServerManager())
{
// Get the Site object
Microsoft.Web.Administration.Site site = manager.Sites.Where(q => q.Name.Equals(siteName)).FirstOrDefault();
// If the site does not exist, throw an exception
if (site == null)
{
throw new Exception("The specified site was not found!");
}
// Stop the site
site.Stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment