views:

96

answers:

1

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?

+4  A: 

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());
Mike Chaliy
+1 Then how do you tell your MVC project to use your custom one instead of the standard is this a Web.config thing?
tyndall
Here you can find example:http://stackoverflow.com/questions/755579/asp-net-mvc-manipulating-url-structure
Mike Chaliy
Mike, These will work great to give me a start. Thanks.
tyndall