Copied to clipboard

Flag this post as spam?

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


  • Kim Larsen 29 posts 72 karma points
    Aug 04, 2010 @ 09:45
    Kim Larsen
    0

    Application_BeginRequest

    I need a bit of code in my Application_BeginRequest, but i can see that it is not possible to create a new global.asax because of the App_global.asax.dll - from what I can find of information it should instead be possible to create a class in App_Code, inheriting from umbraco.Global and then override the Application_BeginRequest byt nothing happens. What am I missing;

    public class MyGlobal : umbraco.Global
    {
      protected override void Application_BeginRequest(object sender, EventArgs e)
      {
        base.Application_BeginRequest(sender, e);
       
        //code
      }
    }

    When debugging I never enters the above code.

    Umbraco 4.5.1 - ASP.NET 3.5

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 04, 2010 @ 09:51
    Matt Brailsford
    0

    Hi Kim,

    Have a read of my blog post on a similar subject, the first one probably isn't any use, but the second 2 show you how you can extend the global.asax

    http://blog.mattbrailsford.com/2010/07/11/registering-an-application-start-event-handler-in-umbraco/

    Another option might be to use a HttpHandler instead, and just register it in your web.config as those trigger on every request anyway.

    Many thanks

    Matt

  • Kim Larsen 29 posts 72 karma points
    Aug 04, 2010 @ 10:32
    Kim Larsen
    0

    Hi Matt

    Your blog post is actually one of the articles I have spent most time studying (maybe you can recognize the name of the class), but as far as I can see I do exactly what is written in "UPDATE – July 11, 2010 19:59" except that I use BeginRequest instead of Start.

    Except for creating the file in the App_Code and inserting the code from my question, or the code from your blog post, will I need to do something else?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 04, 2010 @ 10:38
    Matt Brailsford
    0

    Hmm, maybe I've missed a few steps.

    I'd have a look at Ismails blog, where he sets up log4net via a custom HttpApplication, his seems to be a lot more complete.

    http://ismailmayat.wordpress.com/2009/05/19/integrating-log4net-into-umbraco-site/

    I'll have a look at updating my post with more details.

    Many thanks

    Matt

  • Kim Larsen 29 posts 72 karma points
    Aug 04, 2010 @ 11:01
    Kim Larsen
    0

    The guide requires deleting of the App_global.asax.dll which I have read in other post would be a bad idea, especially in newer versions of Umbraco. Deleting the file would make it much easier as it is then possible to insert my own global.asax - but I see this as the last way out.

    I also tried writing HttpHandler-option but without success - maybe I should try a bit more untill we hopefully find the right solution with inheriting umbraco.Global :)

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 04, 2010 @ 11:03
    Matt Brailsford
    0

    Hi Kim,

    Yea, if it's on every request, I reckon a HTTPHandler is probably your safest bet.

    Let me know if you have any issues

    Many thanks

    Matt

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 04, 2010 @ 11:16
    Ismail Mayat
    0

    Kim,

    In 4.1 onwards you can inherit from global.asax and override the methods so no need to remove  global.asax.dll I see you are using 4.5.1 hence you should be able to override.

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 04, 2010 @ 11:29
    Ismail Mayat
    0

    Kim,

    If you reflector into umbraco dll and take a look at class global you have

    protected virtual void Application_BeginRequest(object sender, EventArgs e)
    {
    }
    

    So create your new class inherit from global and over ride that should then allow your stuff to be hit.

    Regards

     

    Ismail

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Aug 04, 2010 @ 11:35
    Stefan Kip
    0

    That won't work Ismail.

    Just create an HttpModule (derive from IHttpModule) and add it to the web.config, much safer and re-usable!

    (search for IHttpModule to find out more)

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 04, 2010 @ 11:38
    Ismail Mayat
    0

    Really, whole point of putting it in was for situations where you need to tap into global events like wiring up IOC etc we made specific request via codeplex after client requested it. Cant see why it wont work?

    Regards

    Ismail

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 04, 2010 @ 11:40
    Matt Brailsford
    1

    You'd still need a way to tell Umbraco to use your class though wouldn't you? Which is usualy done by modifying the global.asax file to tell it which calss to inherit from.

    Matt

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Aug 04, 2010 @ 11:50
    Ismail Mayat
    0

    Matt,

    RATS!!!!

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft