Tuesday, May 7, 2013

.NET 4.0 Routing

One of the cool features in .NET 4.0 is the RouteCollection object. If your currently using MVC then this is already built-in.  When I first tried to implement this into one of my sites, the main issue I ran across was moving it to the production server.  I made sure my site was running on .NET 4.0 and added "System.Web.Routing.dll" to my bin folder but the routing still wasn't working. As you'll see in my snippet, after creating all my routes I had to create an additional one with "Route.MapPageRoute" for it to work on production.  It seemed as if it needed a starting anchor for everything to work correctly even though it was working fine on my local machine.  I probably could have resolved this issue much easier in IIS if my server was dedicated, but that wasn't the case.  There are probably better ways to do this, but this worked for me at the time.  Anyway, hope this helps anyone having the same issues. Happy Coding!!!

public static void RegisteredRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("Home", "", "~/Default.aspx");   
        routes.Add(new Route("Contact", new ContactRouteHandler()));
    }

No comments:

Post a Comment