Created
March 19, 2012 11:12
-
-
Save CharlTruter/2107864 to your computer and use it in GitHub Desktop.
Stopping a site in IIS using Microsoft.Web.Administration in C#
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
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