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 8910815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:47:04+00:00 2026-06-15T03:47:04+00:00

I have many host names on IIS that point to the same ASP.NET MVC

  • 0

I have many host names on IIS that point to the same ASP.NET MVC app.

www.domain.com
www.domain.co.uk
www.domain.net
...

How can I get the top level domain (es. “.com”) when I set a map route like the following?

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

    ' MapRoute takes the following parameters, in order:
    ' (1) Route name
    ' (2) URL with parameters
    ' (3) Parameter defaults
    routes.MapRoute( _
        "Default", _
        "{controller}/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
    )

End Sub
  • 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-06-15T03:47:06+00:00Added an answer on June 15, 2026 at 3:47 am

    You need to create a custom route. Just inherit Route, override GetRouteData and include routing information which is for the TLD.

    http://msdn.microsoft.com/en-us/library/system.web.routing.route.getroutedata.aspx

    Example

    The route:

    public class RouteWithTld : Route
    {
        public RouteWithTld(string url, IRouteHandler routeHandler) : base(url, routeHandler)
        {
        }
    
        public RouteWithTld(string url, RouteValueDictionary defaults, IRouteHandler routeHandler) : base(url, defaults, routeHandler)
        {
        }
    
        public RouteWithTld(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler) : base(url, defaults, constraints, routeHandler)
        {
        }
    
        public RouteWithTld(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens, IRouteHandler routeHandler) : base(url, defaults, constraints, dataTokens, routeHandler)
        {
        }
    
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var baseData = base.GetRouteData(httpContext);
    
            int pos = httpContext.Request.Url.Host.LastIndexOf('.');
            string tld;
            if (pos == -1)
            {
                if (httpContext.Request.Url.Host == "localhost")
                    tld = "com";
                else
                {
                    throw new InvalidOperationException("You need to handle this case.");
                }
            }
            else
                tld = httpContext.Request.Url.Host.Substring(pos + 1);
    
            baseData.Values.Add("tld", tld);
    
            return baseData;
        }
    }
    

    Mapping it in global.asax:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        /*routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
         * */
    
        var defaults =
            new RouteValueDictionary(new {controller = "Home", action = "Index", id = UrlParameter.Optional});
        routes.Add(new RouteWithTld("{controller}/{action}/{id}", defaults, new MvcRouteHandler()));
    
    }
    

    And accessing the parameter in the controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC. TLD: " + RouteData.Values["tld"];
    
            return View();
        }
    
        public ActionResult About()
        {
            return View();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different domains (let's say www.site1.com and www.site2.com) that point to the
I've recently encountered an error trying to host my asp.net site with IIS. I
I have 1 IIS server that I would like to use to host 2
I have many PowerPoint presentations that I need to be able to add to
I have many flags that I want to store them in an integer, so
I have many MySQL statements that are running under MySQL 4, but not MySQL
I have a single Rails 2.2.2 app that I want to 'share' with multiple
I have a Host which has a many-to-many relationship with services. The relation is
I have my actual site running on one physical server using IIS7 and ASP.NET.
My rails app has Podcast and Track models. Podcasts have many Tracks, Tracks belong

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.