Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7504497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:35:39+00:00 2026-05-29T21:35:39+00:00

I currently have an ASP .NET MVC site that has two domains pointing to

  • 0

I currently have an ASP .NET MVC site that has two domains pointing to it (e.g. http://www.domainA.com and http://www.domainB.com). I would like to change all of my links to use http://www.domainA.com even if http://www.domainB.com is visited.

All of my urls are generated by the built-in Url.Action and Html.ActionLink methods.

I followed the instructions in a previous question but I can’t quite get it working.

Here is my custom route:

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;
    }
}

Here is my custom route handler:

class MyRouteHandler : IRouteHandler
{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        return new MvcHandler(requestContext);
    }
}

Here is my RegisterRoutes method:

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
    );
}

The route is working (i.e. not crashing my site) but when I run it, my urls are just appended to http://localhost… For example, I get “http://localhost:56822/http:/www.domainA.com/Home/Index“.

Does anyone have any idea why this is not working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:35:41+00:00Added an answer on May 29, 2026 at 9:35 pm

    If you’re using IIS 7, it may be better to implement this at web server level.

    This way, the proper status code will be returned to the browser in the HTTP header and your MVC app can deal with its own routing without having to worry about domains and hostnames which, in most cases, is the web server’s job.

    There are two ways to achieve this

    1. Via the IIS administration console

    Open your website in the IIS console and select URL Rewrite and follow these steps:

    1. Create a new rule and set the match URL to wildcard and enter the pattern as your secondary domain
    2. Add a condition where {HTTP_HOST} is equal to the site’s secondary domain.
    3. Set the “action type” to redirect, and enter the pattern you wish to redirect to. “http://mysite.com{R:1}” in this case would map everything after the IP address to its domain equivilent, so mysite.net/mycontent would redirect to mysite.com/mycontent

    2. In your web.config

    <system.webServer>
    <rewrite>
     <rules>
     <rule name="Redirect to mydomain.com" stopProcessing="true">
     <match url=".*"/>
     <conditions>
     <add input="{HTTP_HOST}" pattern="^(www.)?mydomain.net"/>
     </conditions>
     <action type="Redirect" url="http://www.mydomain.com/{R:0}"/>
     </rule>
     </rules>
     </rewrite>
    </system.webServer>
    

    This approach will ensure your subdirectories are mapped and your site remains search engine friendly, with proper response codes being generated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET site that is not currently using MVC but I'm trying
I have an ASP.NET MVC 3 application, WouldBeBetter.com , currently hosted on Windows Azure.
Currently building a site in ASP.NET MVC and have to integrate another site within
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
I currently have an ASP.NET MVC 3 project, plus a class library project, that
I'm currently writing a website in ASP.NET MVC, and my database (which doesn't have
In one of the ASP .Net site we are currently working we have a
I have a Web Role that is using the ASP.NET SQL Membership provider. Currently
I have a project that needs to be done using ASP.NET. Currently, I'm using
I have an ASP.NET MVC 3 site using a custom route for specifying the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.