0

If you wanted to alter the way that routes were processed can you do that in a MVC project OR do you have to alter the MVC Framework?

For example lets say you have the standard code in RegisterRoutes of Global.asax.cs:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

}

But lets say what you really want to happen is to have your custom class intercept all incoming requests and route them in a special way. Can this be done with via Inheriting from a MVC framework class and then customizing, or do you have to actually alter the framework code?

BuddyJoe
  • 69,735
  • 114
  • 291
  • 466

1 Answers1

5

Extending, you just need to write custom RouteHandler.

Look at:

ASP.NET MVC, Manipulating URL Structure

Developing Custom RouteHandler

Or planety other on the web.

EDIT:

You can do even more by extending RouteBase and adding it to routes.

routes.Add("CoolRouter", new CoolRouter());
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mike Chaliy
  • 25,801
  • 18
  • 67
  • 105
  • +1 Then how do you tell your MVC project to use your custom one instead of the standard is this a Web.config thing? – BuddyJoe Jul 20 '09 at 15:28
  • 1
    Here you can find example: http://stackoverflow.com/questions/755579/asp-net-mvc-manipulating-url-structure – Mike Chaliy Jul 20 '09 at 15:29