Possible Duplicate:
How to get RouteData by URL?
public override RouteData GetRouteData(HttpContextBase httpContext)
{
var url = httpContext.Request.Headers["HOST"];
var index = url.IndexOf(".");
if (index < 0)
return null;
var subDomain = url.Substring(0, index);
if (subDomain != "www" && subDomain != "m")
{
var routeData = new RouteData(this, new MvcRouteHandler());
routeData.Values.Add("controller", "Business");
routeData.Values.Add("action", "Display");
routeData.Values.Add("id", subDomain);
return routeData;
}
if (subDomain == "m")
{
var routeData = new RouteData(this, new MvcRouteHandler());
routeData.Values.Add("controller", "Mobile");
routeData.Values.Add("action", "Index");
return routeData;
}
return null;
}
My problem is that when I access xyz.mydomain.com
it is always rerouted to xyz.mydomain.com/Business/Display/xyz
. This is preventing me from going to xyz.mydomain.com/Overview
as it's picking up the subdomain and redirecting.
I have tried using if
statements to determine if a controller is specified, but nothing seems to work. Any suggestions?