2

Can I have a path configured as :

        routes.MapRoute(
        name: "Default",
        url: "{id}.zeko.com",
        defaults: new { controller = "App",
                        action = "GetDetailsById", 
                        id = UrlParameter.Optional
                      }
               );

I want the id as a parameter to my method. Tell me where am I wrong?

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79

3 Answers3

1

ok figured it out myself.....just we have to spilt the domain we have got after each id is created.

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79
0

I'm not entirely sure that this is possible. I believe the routing engine in MVC does not handle domain requests by default. What you can do is add an IIS handler that processes the requests beforehand, or what I have done in Web Forms (and I am not exactly sure how you would accomplish this in MVC) is to call a method to strip out the subdomain in my "Page_Load" method and then work with that variable as required. Below is an example of the function I use, keep in mind my application only expects to work with a single subdomain such as "subdomain.maindomain.com":

private static string GetSubDomain(Uri url)
    {
        try
        {
            string host = url.Host;
            if (host.Split('.').Length > 2)
            {
                int firstIndex = host.IndexOf(".");
                string subdomain = host.Substring(0, firstIndex);

                return subdomain;
            }
        }
        catch
        {

        }

        return string.Empty;
    }
INNVTV
  • 3,155
  • 7
  • 37
  • 71
0

I found this post for you, however it requires knowing each possible subdomain in advance, where as my previous answer allows for dynamic subdomains. Hope these helped!

Is it possible to make an ASP.NET MVC route based on a subdomain?

Community
  • 1
  • 1
INNVTV
  • 3,155
  • 7
  • 37
  • 71