Introducing RouteMagic

asp.net, code, asp.net mvc, open source 0 comments suggest edit

Over the past couple of years, I’ve written several blog posts on ASP.NET Routing where I provided various extensions to routing. Typically such blog posts included a zip download of the binaries and source code to allow readers to easily try out the code.

But that’s always been a real pain and most people don’t bother. But now, there’s a better way to share such code. Moving forward, I’ll be using NuGet packages as a means of sharing my code samples.

In the case of my routing extensions, I’ve compiled them into a solution I call RouteMagic (source is available on GitHub). This solution includes two packages, RouteMagic.Mvc (extensions specific to ASP.NET MVC Routing) and RouteMagic (more general ASP.NET Routing extensions). The RouteMagic.Mvc package depends on the RouteMagic package.

These packages are available in the NuGet feed!

After installing the RouteMagic.Mvc package, you’ll have the following  features available to you.

The source code for the solution contains the following projects:

  • RouteMagic
  • RouteMagic.Mvc
  • RouteMagic.Demo.Web (ASP.NET MVC Web application used to demo these features)
  • UnitTests

This is just a pet project I put together based on various blog posts I’ve written. I’d love to see some of these ideas eventually make it into the Framework. But until then, you’ll probably see these things make it into Subtext for sure!

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

19 responses

  1. Avatar for Nick Berardi
    Nick Berardi January 30th, 2011

    Wow I really like the delegate handler and the groups.
    Do you mind if I use these concepts with my Apache mod_rewrite style overlay for setting up ASP.NET routes?
    github.com/.../RoutingApacheRuleSet.cs
    The delegates would be a great way to allow plugin routes. And the grouping is very easy already, so it would be a natural extension.

  2. Avatar for Bats Ihor
    Bats Ihor January 30th, 2011

    Another one great thing in the NuGet feed! Thank you.

  3. Avatar for haacked
    haacked January 30th, 2011

    @Nick, feel free. I licensed the code under a very liberal Ms-PL license. :)

  4. Avatar for A-Dubb
    A-Dubb January 31st, 2011

    Thanks for the extensions. Will check them out. Keep up the good work MVC team.

  5. Avatar for Daniel
    Daniel February 4th, 2011

    Thanks for making it public :) i might try it.

  6. Avatar for Doug Clutter
    Doug Clutter May 3rd, 2011

    Any reason this wouldn't work with the Azure SDK? Also tried Glimpse and it didn't work either.

  7. Avatar for Thomas Tai
    Thomas Tai August 11th, 2011

    Hi Phil, thanks for the library.
    However it only works on the ASP.NET Development Server. Once I deployed it to IIS7 on my production Windows Server 08 R2 box, routing function just doesn't work any more. What's going on?
    I have already added the follow to my web.config but still doesn't work.
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>

  8. Avatar for What
    What September 1st, 2011

    So you remove the ability to download the source code. How can we get to the demo that you say exist? You have no example of how to execute routemagic so that we can see the trace. So, all we can do is simply download the assembly without any idea of how to use it. Most of us need to debug our routes and will not need handler and grouping which is the only example. Your site says there is an example but since only the assembly is available we dont have access to the demo. Consider making the souce available again.

  9. Avatar for haacked
    haacked September 1st, 2011

    @What, the source is available. http://routemagic.codeplex.com/

  10. Avatar for Andrea
    Andrea December 11th, 2011

    Hello.
    How can I use RouteDebugger to get infos about a 404 error page?
    It looks like my routing map is not properly configured, but I can't find where is the issue.
    Can Route Debugger intercept a 404 error and shows some data?

  11. Avatar for haacked
    haacked December 12th, 2011

    @Andrea, yeah, RouteMagic should intercept every request, unless IIS handles it first.

  12. Avatar for Andrea
    Andrea March 6th, 2012

    Well, I'm still facing issues with this.
    I just want to debug 404 errors, but installing this NuGet package simply doesn't do the trick.
    The old RouteDebugger also doesn't work when I get a 404 error page (it does work with matching routes).

  13. Avatar for Pramod Fanda
    Pramod Fanda December 11th, 2012

    Hi Phil,
    I am getting this error when I try to install nuget.server package in VS 2010 to create a internal hosted nuget website to host internal packages.
    Could not install package 'RouteMagic 1.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
    Any thoughts?

  14. Avatar for haacked
    haacked December 11th, 2012

    Are you using ASP.NET 4?

  15. Avatar for Umbyersw
    Umbyersw January 7th, 2013

    Hi Phil I'm trying to use this however it's not showing up for me and not sure what else to try... I'm starting a new MVC 4 project, Razor view engine, with the Internet Application template chosen. Then, adding the RouteMagic.MVC package, and running - I don't see anything extra on the page. I've tried with both .NET 4 and 4.5 and in both IIS/IIS Express. Hopefully you can spot my mistake or perhaps there is some key setting that I am missing? Thanks!

  16. Avatar for haacked
    haacked January 10th, 2013

    Please log an issue against the repository https://github.com/Haacked/... and I'll try and find time to look into it. Does it work for you if you create a brand new ASP.NET MVC 3 project? It could be an incompatibility with MVC 4.

  17. Avatar for thomen
    thomen July 25th, 2013

    Hi I was just wondering if you had a suggested approach for the scenario where a user can pick a subdomain name and then do some theming based on that subdomain in mvc4? would RouteMagic route based on subdomain or would it more be an issue of selecting a theme based on the user's subdomain via some kind of routing of the incoming request?

    Cheers,
    Tom

  18. Avatar for haacked
    haacked July 25th, 2013

    The point of routing is to _route_ the request to a controller action. My guess is that you don't have different controllers and actions for the theme. So for the most part, routing is not really involved.

    In theory, you could have a custom route that always returns null (indicating it did not match the request) that you make sure is 1st in the route collection. It could look at the subdomain, lookup the theme, and then add the theme value to the route data so it could be passed in as a parameter to any action. But that's not the only way to handle it.

  19. Avatar for thomen
    thomen July 25th, 2013

    Hi Phil,

    Thanks so much for the reply. I was looking at emulating the scenario similar to oztix where you have a theme that is applied to a section of the site (in their case a purchase workflow) based on the subdomain and the products list is generated based on that.. I'm assuming the subdomain is some kind of username parameter passed in through the routing and verified and then used to form the basis of a skin. i.e. <user>.domain.com like they do for karnivool.oztix.com.au where they have a themed user page and workflow on the subdomain vs their oztix.com would it be some kind of subdomain routing where the username is passed in as a route argument? I guess then that lends the questions how would you setup username.domain.com on the fly as well like lots of ruby apps do i.e. shopify? some kind of db table of users which you validate against for routing?

    I've found this blog post here http://lukesampson.com/post... and similar here http://blog.tonywilliams.me...

    but wondering if you had a suggested approach mvc4 wise?