Skip to content

Instantly share code, notes, and snippets.

@CharlTruter
CharlTruter / gist:2110398
Created March 19, 2012 12:35
How to change bindings on a site in IIS using C#
void ChangeSiteBinding(string siteName, string oldBindingValue, string newBindingValue, string protocol)
{
using (ServerManager manager = new ServerManager())
{
// Find the site by name from IIS
Microsoft.Web.Administration.Site site = manager.Sites.Where(q => q.Name == siteName).FirstOrDefault();
if (site == null)
{
throw new Exception("The specified site name does not exist in IIS!");
}
@CharlTruter
CharlTruter / gist:2109322
Created March 19, 2012 12:01
Loading a site's content in C# using backend code
string GetSiteContent(string url)
{
// Create the web request for the url passed to the method
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
// For the sake of this example, we'll be using the GET method.
// For other options, please see http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.method.aspx
myRequest.Method = "GET";
// Get the response and store it in a WebResponse object
@CharlTruter
CharlTruter / gist:2108690
Created March 19, 2012 11:41
Starting a site in IIS using Microsoft.Web.Administration in C#
void StartSite(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)
{
@CharlTruter
CharlTruter / gist:2107864
Created March 19, 2012 11:12
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)
{
void RunProcess(string path)
{
using (Process process = new Process())
{
// This sets up the output redirection
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
// Specify the path to the file here
process.StartInfo.FileName = path;
void RunProcess(string path)
{
using (Process process = new Process())
{
// This sets up the output redirection
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
// Specify the path to the file here
process.StartInfo.FileName = path;