Skip to content

Instantly share code, notes, and snippets.

@CharlTruter
CharlTruter / gist:2110398
Created Mar 19, 2012
How to change bindings on a site in IIS using C#
View gist:2110398
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 Mar 19, 2012
Loading a site's content in C# using backend code
View gist:2109322
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 Mar 19, 2012
Starting a site in IIS using Microsoft.Web.Administration in C#
View gist:2108690
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 Mar 19, 2012
Stopping a site in IIS using Microsoft.Web.Administration in C#
View gist:2107864
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)
{
View gist:2028533
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;
View gist:2028487
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;