asp.net - subdomain does not work with default route -


i have created sub-domain route class in routeconfig.cs as:

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

i updated registerroutes function :

public static void registerroutes(routecollection routes)         {             routes.ignoreroute("{resource}.axd/{*pathinfo}");              routes.add(new subdomainroute());              routes.maproute(                 name: "default",                 url: "{controller}/{action}/{category}/{subcategory}/{lowcategory}/{id}",                 defaults: new { controller = "home", action = "index",category=urlparameter.optional,subcategory=urlparameter.optional,lowcategory=urlparameter.optional, id = urlparameter.optional }             );         } 

my index function :

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

now link http://localhost:29808/home/index/mobiles/htc/m8/3 working fine subdomain not working electronics.localhost:29808/home/index/mobiles/htc/m8/3. (it shows null in category , subcategory). else if have include make work?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -