Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kris Dyson 54 posts 79 karma points
    Mar 08, 2013 @ 17:14
    Kris Dyson
    0

    ASP.NET Routing integration within UmbracoApplication subclass

    Hi there, I'm in the process of upgrading my client's v4.7.2 Umbraco site to v6.0.2.

    I'm proceeding along the upgrade paths and I have hit a problem at version 4.10.1.

    We have a custom IHttpModule which uses ASP.NET routing to override the Umbraco routing in v4.7.2.  Now that Umbraco supports MVC, the architecture has changed and our custom routes no longer work.  Some of the route are static, like /api, /filters, etc, however, we also have about 150 dynamic routes... i.e., they're read from the database and are essentially redirectors for a very old version of the website.

    This is the code for the Register Routes function:

    public static void RegisterRoutes()
    {
    var routes = RouteTable.Routes;

    routes.Clear();

    using (var dc = new OrigEntities())
    {
    dc.Redirectors.ToList().ForEach(x =>
    {
    var name = "dynroute" + x.id;
    routes.MapHttpHandler<Handlers.Redirector>(name: name, url: x.OldUrl, dataTokens: new { url = x.NewUrl });
    });
    }

    routes.MapHttpRoute(name: "RPCApi",
    routeTemplate: "rpcapi/{action}/{id}",
    defaults: new { id = RouteParameter.Optional, controller = "RPCApi" }
    );

    routes.MapHttpHandler<Handlers.RssFeed>(url: "rss");
    routes.MapHttpHandler<Handlers.XmlFeed>(url: "xml");
    routes.MapHttpHandler<Handlers.XmlFeed>(url: "aspx/rss.aspx"); // old legacy rss url (actually an xml feed)
    routes.MapHttpHandler<Handlers.Triangle>(url: "triangle/{colour}/{dimensions}");
    routes.MapHttpHandler<Handlers.WorldPayReturn>(url: "worldpayreturn");
    routes.MapHttpHandler<Handlers.EventDetail>("EventDetail",
    "events/{type}/{city}/{locality}/{date}/{templateid}/{id}/{page}", new { page = "info" }, null);

    routes.MapPageRoute("filter-page", "filters/{when}/{city}/{locality}/{category}/{venue}/{venueid}", "~/aspx/filters.aspx", false, new RouteValueDictionary(
    new
    {
    when = "anytime",
    city = "any-city",
    locality = "any-locality",
    category = "any-category",
    venue = "any-venue",
    venueid = "any"
    }));
    }

     

    Is it going to be possible to create dynamic routes on the application's start up? I have already integrated this code within the OnApplicationStarted method of an UmbracoApplication instance, but it has no effect for either static or dynamic routes.

    thanks for your help

    Kris

     

  • Kris Dyson 54 posts 79 karma points
    Mar 08, 2013 @ 18:14
    Kris Dyson
    0

    Hi there, I have now upgraded to v6.0.2 just to see if any bug fixes would have any effect.  They appear to have had some effect.  My static routes now work using the code above AND some of my dynamic routes.

    However, I'm finding that routes that end in *.html or *.htm do not process, whereas routes that have no extension or have the extension *.aspx process just fine.

    Anyone any ideas why this might be?  As an example: "/about_us.html" gets a HTTP 404 whereas another dynamic route, "/xml" or "/aspx/rss.aspx" works fine.

    thanks

    Kris

  • Kris Dyson 54 posts 79 karma points
    Mar 08, 2013 @ 19:07
    Kris Dyson
    0

    Hi there, just to let you know, I made an error whilst merging the web.config.

    I forgot to include in webServer/modules:

          <remove name="UrlRoutingModule-4.0"/>
          <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />

    This ensures that the managed url routing modue is fired for all requests, including for apparently static content, like a /test.html request

     

     

Please Sign in or register to post replies

Write your reply to:

Draft