Config based routing

Last post 03-19-2008 3:49 PM by DanFinch. 3 replies.

Sort Posts:

  • Config based routing

    03-13-2008, 4:44 PM

    I suspect I can figure this out on my own after using the framework for a bit, but I was wondering if anyone had developed a web.config based routing implementation?

    Something like:

    <routing>
      <route command="EditEmployee" controller="Employee" action="Edit"/>
      <route command="AddEmployee" controller="Employee" action="Add"/>
      <route command="JumpTo" controller="Default" action="JumpTo"/>
    </routing>

    In which we're no longer mapping directly to controllers and we standardize the code in the global.asax. I know the current implementation has a pass-through nature in the controllerName/actionName/id pattern, but I'm wondering if we can't entirely abstract the pattern away from code and put it into the config file.

    So if someone wants to map it differently, they can...including putting the pattern into configuration:

    <routing pattern="{controller}/{action}/{id}" mapped="false" />

    or

    <routing pattern="{command}" mapped="true">
        <map command="EditEmployee" controller="Employee" action="Edit"/>
    </routing>

    Am I crazy?

    David C.

    Filed under:
  • Re: Config based routing

    03-13-2008, 6:16 PM
    Answer
    • Loading...
    • csainty
    • Joined on 03-12-2008, 2:41 AM
    • Newcastle, Australia
    • Posts 48

    I read a blog post about this 10 minutes ago

    http://weblogs.asp.net/fredriknormen/archive/2008/03/11/asp-net-mvc-framework-2-define-routes-in-web-config.aspx

    Havn't looked at the code yet, but its a nice idea.

  • Re: Config based routing

    03-13-2008, 6:48 PM
    • Loading...
    • ajma
    • Joined on 10-20-2002, 11:07 PM
    • Redmond, WA
    • Posts 10

    I like this idea.

    I was wondering why routing wasn't controlled by an xml file.

  • Re: Config based routing

    03-19-2008, 3:49 PM
    • Loading...
    • DanFinch
    • Joined on 03-19-2008, 3:45 PM
    • Posts 11

    http://www.codeplex.com/RouteBuilder

    This is meant for the older MVC release, and I haven't tried it, so.

    Good luck
     

    Dan Finch 

Page 1 of 1 (4 items)