Copied to clipboard

Flag this post as spam?

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


  • Bogdan 250 posts 427 karma points
    Jul 24, 2013 @ 14:47
    Bogdan
    0

    Extending Global.asax to create custom MVC routes

    Hi,

    I'm trying to add a custom route based on the instructuions from here http://our.umbraco.org/documentation/Reference/Mvc/custom-routes

    The problem is that OnApplicationStarted doesn't fire.

    public class Global : Umbraco.Web.UmbracoApplication
    {
        protected override void OnApplicationStarted(object sender, EventArgs e)
        {
            base.OnApplicationStarted(sender, e);
            RegisterRoutes(RouteTable.Routes);
        }
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("SiteMapXml", "sitemap.xml", new { controller = "SiteMapXmlSurface", action = "SiteMapXml" });
        }
    }

    Any ideas what I'm doing wrong? The site is on V 6.1.2.2 installed in an MVC 4 project as a NuGet package.

    Thanks!

  • David Prothero 23 posts 106 karma points
    Aug 01, 2013 @ 21:54
    David Prothero
    0

    I'm having the exact same issue and cannot determine the cause. I'm on 6.1.3, also installed in an MVC4 project as a NuGet package.

    Global.asax:

    <%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>

    Global.asax.cs:

    using NS3.WebApp;
    using System;
    using System.Web.Routing;

    public class Global : Umbraco.Web.UmbracoApplication
    {
    protected override void OnApplicationStarted(object sender, EventArgs e)
    {
    base.OnApplicationStarted(sender, e);
    System.IO.File.WriteAllText("C:\\scripts\\blah.txt", "hello! " + DateTime.Now.ToString());
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    }
    }

    I added the line to write to a file to confirm whether or not it was getting called. It is not getting called at all.

    David

  • Jade Montagu 8 posts 71 karma points
    Aug 02, 2013 @ 07:47
    Jade Montagu
    100

    So close!

    You need to update your Global.asax Inherits attribute to reference your new Global class.

    e.g

    <%@ Application Codebehind="Global.asax.cs" Inherits="MyNewApp.Global" Language="C#" %>
    

    Hope that works :)

  • Bogdan 250 posts 427 karma points
    Aug 02, 2013 @ 09:15
    Bogdan
    0

    Thanks a lot Jade, that was it!

  • David Prothero 23 posts 106 karma points
    Aug 02, 2013 @ 17:13
    David Prothero
    0

    Success! Thanks Jade.

  • KK14 2 posts 22 karma points
    Dec 08, 2014 @ 12:27
    KK14
    0

    I have same parser error in umbraco v6 and I applied same solution but still get this error.

  • Tajamal 87 posts 175 karma points
    Jan 28, 2016 @ 11:42
    Tajamal
    0

    this does not work with Umbraco 7.3.1 ? any one can help me out...

Please Sign in or register to post replies

Write your reply to:

Draft