c# - Subdomain redirecting to root in MVC 3 -


i'm experiencing frustratingly perplexing issue regards subdomains on mvc 3 application. using code below, subdomain routes me root of domain everytime.

when enter subdomain.mydomain.com routes me domain.com?nr=0. can't find why, or in code, it's appending querystring value.

 public class subdomainroute : routebase     {         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 (!string.isnullorempty(subdomain) && subdomain != "www" && subdomain != "mydomain")             {                 var routedata = new routedata(this, new mvcroutehandler());                 routedata.values.add("controller", "external");                  routedata.values.add("action", "coolaction");                  routedata.values.add("subdomain", subdomain);                  return routedata;             }             else                 return null;         }  } 

i disabled forms authentication, didn't fix it. have url rewrite prepends www. requests, if www. missing - removed , didn't fix it. below registerroutes of global.asax:

    public static void registerroutes(routecollection routes)     {         routes.ignoreroute("{resource}.axd/{*pathinfo}");         routes.ignoreroute("elmah.axd");          routes.add(null, new subdomainroute());          routes.maproute(             "default", // route name             "{controller}/{action}/{id}", // url parameters             new { controller = "home", action = "index", id = urlparameter.optional },             new[] { "myproject.ui.web.controllers" }         );         routes.maproute("notescontroller",                         "notes/{notedestinationtype}/{notedestinationguid}",                         new { controller = "notes", action = "savenote" });     } 

i've been banging head on day long , give up. i'm asking help. tia.

i think missing regex.split(url); see more

            var url = httpcontext.request.rawurl;             regex regex = new regex("/");             string[] substrings = regex.split(url);             var index = host.indexof(".");             var subdomain = host.substring(0, index); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -