Copied to clipboard

Flag this post as spam?

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


  • Nick Renny 31 posts 63 karma points
    Nov 26, 2012 @ 13:40
    Nick Renny
    1

    Custom Global.asax class (4.11)

    So do I just have to change the reference in the global.asax file to use this instead of the global.asax.cs code behind?

  • Funka! 398 posts 661 karma points
    Feb 08, 2013 @ 20:09
    Funka!
    0

    Have the same questions here. Did you ever figure this out?

    It seems if you've installed the site from binaries, there is no global.asax.cs code behind, which i'm guessing is compiled into one of the DLLs so thus we need to provide our own.  I was looking at this page http://our.umbraco.org/documentation/reference/mvc/custom-routes but it doesn't go into enough detail. Was just wondering what others have been doing. Thanks!

     

  • Funka! 398 posts 661 karma points
    Feb 08, 2013 @ 20:12
    Funka!
    0

    The plot thickens. Cannot even find any file named "global.asax.cs" in the latest source code; will try just dumping in one from a new MVC project, but surely there must be some base routing Umbraco needs to start with?

  • Nick Renny 31 posts 63 karma points
    Feb 08, 2013 @ 21:15
    Nick Renny
    0

    Hi yes I did work it out you need to create a new class that inherits from Umbraco.Web.UmbracoApplication

     

      publicclassdiam_planogram : Umbraco.Web.UmbracoApplication

      {

        protected override void OnApplicationStarted(object sender, EventArgs e)

        {

          base.OnApplicationStarted(sender, e);

     

      }

    }

  • Funka! 398 posts 661 karma points
    Jul 16, 2013 @ 00:59
    Funka!
    0

    Following up for posterity:  Nick is correct, you will want to create your own custom class that inherits from Umbraco.Web.UmbracoApplication and the implement the override for the OnApplicationStarted event as he showed above. If you installed Umbraco from binaries (rather than working with umbraco inside of a Visual Studio project) you can put this file into the magic /App_Code folder for it to be recognized.

    I'm not sure if that's all you need to do, but what I've also been doing for good measure is changing the "global.asax" markup (NOT its .cs code-behind that we're talking about, but the one-line file that appears in the site root) and change the "Inherits" attribute from Umbraco.Web.UmbracoApplication to whatever you named your custom class, e.g., Inherits="MyCustomUmbracoApplication".

  • Davide 9 posts 29 karma points
    Jan 22, 2015 @ 08:39
    Davide
    0

    Hi all,

    I'm having the same issue by migrating from 4.9.0 to 4.11.10. I have a custom Global.asax file as shown below, with the Application_BeginRequest filled with my code:

    public class Global : Umbraco.Web.UmbracoApplication

        {

            public void Init(HttpApplication application)

            {

                application.PreRequestHandlerExecute += new EventHandler(application_PreRequestHandlerExecute);

                application.EndRequest += (new EventHandler(this.Application_EndRequest));

                //application.Error += new EventHandler(Application_Error); // Overriding this below

            }

     

            private void application_PreRequestHandlerExecute(object sender, EventArgs e)

            {

                

            }

     

            private void Application_BeginRequest(object sender, EventArgs e)

            {

                ERAUtils.RewriteURL();

            }

     

            private void Application_EndRequest(object sender, EventArgs e)

            {

                

            }

     

            protected new void Application_Error(object sender, EventArgs e)

            {

                

            }

     

            protected override void OnApplicationStarted(object sender, EventArgs e)

            {

                base.OnApplicationStarted(sender, e);

            }        

     

            protected void Application_AuthenticateRequest(object sender, EventArgs e)

            {

     

            }     

                   

        }

    I also properly changed the markup of the Global.asax into:

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

    Despite all my attempts I continue to have a "Object reference not set to an instance of an object" issue on my home page in the following umbraco event:

    umbraco.UmbracoDefault.OnPreInit(EventArgs e)

    Any suggestions?

    Thank you very much in advance to all of you...

Please Sign in or register to post replies

Write your reply to:

Draft