301 redirect to all pages in a site with ASP.NET
<p>I'd like to set up a 301 redirect from a .co.uk site to a .com site, keeping the same pages.</p>

<p>So someone going to mydomain.co.uk/pages/about should get redirected to mydomain.com/pages/about</p>

<p>I'm using ASP.NET and IIS 7.0 and not having much luck.  I tried setting a custom 404 file that has a redirect in it like so:</p>

<pre><code>    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(".co.uk"))
    {
        HttpContext.Current.Response.Status = "301 Moved Permanently";
        HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace(
                ".co.uk",
                ".com"));
    }
</code></pre>

<p>however my 404 page isn't being called when I go to a URL such as /pages/about.  I have the following in my web.config:</p>

<pre><code>&lt;configuration&gt;
  &lt;system.web&gt;
    &lt;customErrors mode="On" defaultRedirect="404.aspx"/&gt;
  &lt;/system.web&gt;
&lt;/configuration&gt;
</code></pre>

<p>Can anyone assist please?</p>
