Friday, November 11, 2011

Redirect All Request to Another URL Programmatically

The following code samples configure the Default Web Site to redirect all requests to "http://www.contoso.com" using an HTTP 302 status code.



using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");

         ConfigurationSection httpRedirectSection = config.GetSection("system.webServer/httpRedirect");
         httpRedirectSection["enabled"] = true;
         httpRedirectSection["destination"] = @"http://www.contoso.com";
         httpRedirectSection["exactDestination"] = false;
         httpRedirectSection["httpResponseStatus"] = @"Found";

         serverManager.CommitChanges();
      }
   }
}

HTTP Redirection in IIS 7 on Windows Server 2008

HTTP Redirection in IIS 7 on Windows Server 2008: "HTTP Redirection in IIS 7 on Windows Server 2008"

Redirect HTTP to HTTPS with IIS 7 | IIS Aid

Redirect HTTP to HTTPS with IIS 7