asp.net mvc - MVC 4 catch all route never reached -


when attempting create catch route in mvc 4 (something i've found several examples of, , based code on) returns 404 error. i'm running on iis 7.5. seems straight forward solution, missing?

one note, if move "catchall" route above "default" route works. of course none of other controllers ever reached.

here code:

route.config:

        routes.maproute(             name: "default",             url: "{controller}/{action}/{id}",             defaults: new { controller = "home", action = "index", id = urlparameter.optional }         );          routes.maproute(             "catchall",             "{*dynamicroute}",             new { controller = "catchall", action = "choosepage" }         ); 

controller:

public class catchallcontroller : controller {      public actionresult choosepage(string dynamicroute)     {         viewbag.path = dynamicroute;         return view();     }  } 

since ultimate goal of creating catchall route able handle dynamic urls , unable find direct answer original issue above, approached research different perspective. in doing came across blog post: custom 404 when no route matches

this solution allows handling of multiple sections within given url (i.e. www.mysite.com/this/is/a/dynamic/route)

here final custom controller code:

public override icontroller createcontroller(system.web.routing.requestcontext requestcontext, string controllername)  {      if (requestcontext == null)      {          throw new argumentnullexception("requestcontext");      }       if (string.isnullorempty(controllername))      {          throw new argumentexception("missingcontrollername");      }       var controllertype = getcontrollertype(requestcontext, controllername);       // 404 returned      // replaced route catchall controller      if (controllertype == null)      {         // build dynamic route variable segments         var dynamicroute = string.join("/", requestcontext.routedata.values.values);          // route catchall controller         controllername = "catchall";         controllertype = getcontrollertype(requestcontext, controllername);         requestcontext.routedata.values["controller"] = controllername;         requestcontext.routedata.values["action"] = "choosepage";         requestcontext.routedata.values["dynamicroute"] = dynamicroute;      }       icontroller controller = getcontrollerinstance(requestcontext, controllertype);      return controller;  } 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -