title: How to force a single domain to be used for ASP.NET MVC site?
body: <p>I currently have an ASP .NET MVC site that has two domains pointing to it (e.g. www.domainA.com and www.domainB.com). I would like to change all of my links to use www.domainA.com even if www.domainB.com is visited.</p>
  
  <p>All of my urls are generated by the built-in Url.Action and Html.ActionLink methods.</p>
  
  <p>I followed the instructions in a <a href="https://stackoverflow.com/questions/7685738/asp-net-mvc-change-domain-used-by-url-action">previous question</a> but I can't quite get it working.</p>
  
  <p><strong>Here is my custom route</strong>:</p>
  
  <pre><code>public class MultipleDomainRoute : System.Web.Routing.Route
  {
      public MultipleDomainRoute(string url, IRouteHandler routeHandler)
          : base(url, routeHandler)
      {
      }
  
      public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
      {
          VirtualPathData path = new VirtualPathData(this, "http://www.domainA.com/" + values["controller"] + "/" + values["action"]);
          return path;
      }
  }
  </code></pre>
  
  <p><strong>Here is my custom route handler:</strong></p>
  
  <pre><code>class MyRouteHandler : IRouteHandler
  {
      public IHttpHandler GetHttpHandler(RequestContext requestContext)
      {
          return new MvcHandler(requestContext);
      }
  }
  </code></pre>
  
  <p><strong>Here is my RegisterRoutes method:</strong></p>
  
  <pre><code>public static void RegisterRoutes(RouteCollection routes)
  {
      routes.Add(new MultipleDomainRoute("{controller}/{action}/{id}", new MyRouteHandler()));
  
      routes.MapRoute(
          "Default",                                              // Route name
          "{controller}/{action}/{id}",                           // URL with parameters
          new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
      );
  }
  </code></pre>
  
  <p>The route is working (i.e. not crashing my site) but when I run it, my urls are just appended to <a href="http://localhost" rel="nofollow noreferrer">http://localhost</a>... For example, I get "<a href="http://localhost:56822/http:/www.domainA.com/Home/Index" rel="nofollow noreferrer">http://localhost:56822/http:/www.domainA.com/Home/Index</a>".</p>
  
  <p>Does anyone have any idea why this is not working?</p>