title: Custom HttpHandler to redirect to different websites for single signon experience
body: <p>Here's my situation:</p>
  
  <p>I have a number of separate websites (which have the same basic format but different authentication logins) - not one website with several folders with apps, separate web applications.</p>
  
  <p>I have a client whose site has links to these websites, but when they click on these links they have to login/authenticate with each one.</p>
  
  <p>So they have links to my sites like:</p>
  
  <pre><code>ricksite1.com?customerid=1
  ricksite2.com?customerid=5
  ricksite3.com?customerid=1000
  </code></pre>
  
  <p>To avoid all of this manual authentication, they want to implement single sign on using a federated identity provider, so that when they click on these links they don't have to manually authenticate each time.</p>
  
  <p>Putting aside the federated mechanism for the moment, I decided that I would prototype simply and create a website with a custom http handler that would redirect the request to the appropriate website based on a querystring parameter called site.</p>
  
  <p>So theoretically I could hit this new site as follows, and it would redirect to ricksite1.com:</p>
  
  <p>redirectsite.com?site=1&amp;customerid=1 would redirect to ricksite1.com?customerid=1</p>
  
  <p>When I try this, I get the error: Invalid path for child request 'ricksite1.com'. A virtual path is expected.</p>
  
  <p>How can I fix this?</p>
  
  <p>Here's the http handler:</p>
  
  <pre><code>public class RedirectHttpHandler:IHttpHandler
      {
          private Dictionary&lt;string, Uri&gt; Sites = new Dictionary&lt;string, Uri&gt;
              {
                  {"1", new Uri("http://ricksite1.com")},
                  {"2", new Uri("http://ricksite2.com")},
                  {"3", new Uri("http://ricksite3.com")}
              };
  
          public void ProcessRequest(HttpContext context)
          {
              string site = context.Request.QueryString["site"];
  
              if (!String.IsNullOrEmpty(site) &amp;&amp; Sites.Keys.Contains(site))
              {
                  context.Server.Transfer(Sites[site].AbsoluteUri, true);
              }
          }
     }
  </code></pre>
  
  <p>with the config file:</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
      &lt;httpHandlers&gt;
        &lt;add verb="*" path="*"
          type="RedirectSite.RedirectHttpHandler, RedirectSite, Version=1.0.0.0, Culture=neutral" /&gt;
      &lt;/httpHandlers&gt;
  
    &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>