Asp.net 子域不使用默认路由

Asp.net 子域不使用默认路由,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我在RouteConfig.cs中创建了一个子域路由类,如下所示: public class SubdomainRoute : RouteBase { public override RouteData GetRouteData(HttpContextBase httpContext) { if (httpContext.Request == null || httpContext.Request.Url == null)

我在
RouteConfig.cs
中创建了一个子域路由类,如下所示:

public class SubdomainRoute : RouteBase
    {
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            if (httpContext.Request == null || httpContext.Request.Url == null)
            {
                return null;
            }
            var host = httpContext.Request.Url.Host;
            var index = host.IndexOf(".");
            string[] segments = httpContext.Request.Url.PathAndQuery.TrimStart('/').Split('/');
            if (index < 0)
            {
                return null;
            }
            var subdomain = host.Substring(0, index);
            string[] blacklist = { "www", "yourdomain", "mail","localhost" };
            if (blacklist.Contains(subdomain))
            {
                return null;
            }
            string controller = (segments.Length > 0) ? segments[0] : "Home";
            if (controller == "")
                controller = "Home";
            string action = (segments.Length > 1) ? segments[1] : "Index";
            var routeData = new RouteData(this, new MvcRouteHandler());
            routeData.Values.Add("controller", controller);
            routeData.Values.Add("action", action);
            routeData.Values.Add("subdomain", subdomain);
            return routeData;
        }
        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            return null;
        }
    }
我的索引函数是:

public string Index(string category, string subcategory, string lowcategory,int? id)

现在链接
http://localhost:29808/Home/Index/mobiles/Htc/M8/3
工作正常,但与子域一起,其不工作
电子设备。本地主机:29808/Home/Index/mobiles/HTC/M8/3
。(类别和子类别中显示空值)。如果必须包含哪些内容才能使其正常工作?

您是否收到空引用异常?不,我没有收到任何异常
public string Index(string category, string subcategory, string lowcategory,int? id)