Copied to clipboard

Flag this post as spam?

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


  • Scott Blomfield 16 posts 21 karma points
    Mar 19, 2009 @ 22:39
    Scott Blomfield
    1

    Need to access events in the global

    I have need to access some events in the global.asax - but I'm not seeing any particular way to do this short of recompiling umbraco. I really don't want to have a custom version of umbraco running for this website, does anyone have any ideas how I might be able to get to these events?

    Right now, I specifically need ProfileOnMigrateAnonymous, but I could potentially see needing ApplicationStart, or Session_Start in the future too.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 19, 2009 @ 23:19
    Ismail Mayat
    0

    sblomfield,

    not sure if this will work but could you not drop a class into the App_code dir that inherits from System.Web.HttpApplication and implement events there? although not sure how that would tie in with events that have already been handled in global.asax?

    Regards

    Ismail

  • Scott Blomfield 16 posts 21 karma points
    Mar 20, 2009 @ 17:41
    Scott Blomfield
    0

    Ismail,

    Without the Global.asax file pointing to my class I don't think that my class would ever get instantiated. But you gave me a good idea... :)

    I'm going to try to create a new class that inherits from umbraco.Global, and then point Global.asax at this new class. I think then that:

    a) Umbraco will continue to get the events it needs,
    b) I will not have to modify and recompile umbraco, forcing the client to keep diffs.
    c) I will (should) get access to the events I need.

    From what I have tested, I think this should work. I had hoped that umbraco would expose these things, but having looked at the code to global, I very much doubt it.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 20, 2009 @ 17:50
    Ismail Mayat
    0

    sblomfield,

    Awesome. Let us know how you get on. I have in the past wanted to put in an IOC container and a log4net into some external stuff i was doing that i was using in umbraco but had the same issue as you when it came to the global.asax, couple of other people have posted similar things.

    So if it works that would be brilliant.

    Regards

    Ismail

  • Scott Blomfield 16 posts 21 karma points
    Mar 20, 2009 @ 18:38
    Scott Blomfield
    0

    Ismael,

    Testing shows that it works, but there is an obvious caveat:

    You can't use any event that is already used inside Umbraco's Global.asax.cs file, as the functions in that file are not declared as virtual; i.e. You cannot override them.

    Anything that is not already declared in the existing global is fair game.

    On a side note - the only thing in that file that really looks like it does anything is the ApplicationEnd event. The rest are empty, or in the case of SessionStart appears to not be doing anything unless I have missed something, and "new Session();" actually accomplishes something non-obvious - in which case a comment above it would really help document that.

    Niels/Per ... any thoughts with regards to removing the unused methods, or at least making them virtual for the next release?

    Thanks,

    Scott

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 20, 2009 @ 19:59
    Ismail Mayat
    0

    Scott,

    The only other thing is becuase the global.asax has been customised you would need to remember not overwrite during upgrade, still better than modifying core code. Might be worth putting a request into codeplex regarding making methods virtual. Put link in to it in post i'll vote for it!

    Regards

    Ismail

  • tarekahf 215 posts 153 karma points
    Apr 06, 2009 @ 07:36
    tarekahf
    0

    (Note: Copied from a previous post for the sake of clarity).

    I am using Umbraco 4.0.0.

    I need to add the following method to a "Global.asax" file under Umbraco Website Folder:

    [code]Protected Sub ApplicationAcquireRequestState( _
    ByVal sender As Object, ByVal e As System.EventArgs)

    Dim principal As System.Security.Principal.IPrincipal
    Try
    principal = _
    CType(Session("CslaPrincipal"), System.Security.Principal.IPrincipal)

    Catch
    principal = Nothing
    End Try

    If principal Is Nothing Then
    ' didn't get a principal from Session, so
    ' set it to an unauthenticted PTPrincipal
    CSLAxx.Library.Security.xxPrincipal.Logout()
    'FormsAuthentication.SignOut
    Else
    ' use the principal from Session
    Csla.ApplicationContext.User = principal
    End If

    End Sub[/code]
    This is required because I am integrating the Custom CSLA .NET Authentication with Umbraco Membership Provider. This method "Application
    AcquireRequestState" is required to avoid initialization the Principal/Identity Object every time the website is accessed, ie, to improve performance.

    If I do not add this file "Global.asax", everything else work fine, and the only problem is that the creation of the Identity and Principal objects will occur on every visit to the website for every user, which is really a bad thing.

    However, after I add the Global.asax to my Umbraco Website, I will get this error as soon as I try to access the website:

    [quote]Server Error in '/' Application.

    --------------------------------------------------------------------------------

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30560: 'globalasax' is ambiguous in the namespace 'ASP'.

    Source Error:



    Line 94: Public Sub New()
    Line 95: MyBase.New
    Line 96: If (Global.ASP.global
    asax.initialized = false) Then
    Line 97: Global.ASP.globalasax.
    initialized = true
    Line 98: End If


    Source File: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\d9ed7379\566fad7a\Appglobal.asax.pxvuwuud.0.vb Line: 96 [/quote]
    Any one could recommend a resolution or a work around to solve this problem.

    I have never worked with HTTP Modules inside a class in app_code, so I appreciate giving me some examples or hints.

    Thank you.

    Tarek.

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Apr 06, 2009 @ 09:13
    Richard Soeteman
    0

    Hi,

    In the Appcode file you can create a class that Implements IHttpModule Then you can override the methods. Check out this post that explains how to build a HTTPModule and how to configure it when you use the appcode folder instead of a seperate DLL.

    Cheers,

    Richard

  • Ricardo Gomes 22 posts 42 karma points
    Oct 15, 2009 @ 13:26
    Ricardo Gomes
    0

    Hello,

     

    thank you for the posts, however I was not able to access the method Application_Start from the IHttpModule as well as the methods Application_End, Session_Begin and Session_Start and Session_End. I searched a bit and found out that through the implementation of an IHttpModule it is not possible.

    I need to overide (put some logic) the Application_Start method, is there any alternative?

    thanks in advance,

    Ricardo

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    May 26, 2010 @ 21:48
    Chris Houston
    0

    Hi All,

    Did anyone find a solution to this?

    I also need to add some code to the Application_Start is this possible?

    Cheers,

    Chris

  • Aaron Powell 1708 posts 3046 karma points c-trib
    May 27, 2010 @ 01:01
    Aaron Powell
    0

    Why can't you just inherit from the HttpApplication class, repoint the global.asax to use yours and ignore the Umbraco one.

    The Umbraco one does nothing anyway.

    We've got 2 custom implementations of the HttpApplication in the Snapshot assemblies.

    I have modified the 4.1 version so that it the Application_State is virtual and you can inherit from the umbraco.Global class.

  • moseeds 13 posts 29 karma points
    May 27, 2010 @ 01:14
    moseeds
    0

    I've created another website project with its own custom global asax events. The the resulting project dll works fine with umbraco by dumping it into the \bin folder of our website. I'm not sure if this is what you're looking for thought so apologies in advanced.

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    May 27, 2010 @ 02:10
    Chris Houston
    1

    Hi Mo / Slace,

    Thank you both for your reply.

    I just thought I'd let you know I've cracked it, finally!

    The problem was the App_global.asax.dll was in the BIN folder, I have removed this and my conflict disappeared and my Application_Start is now working.

    @Slace.. Am I right from your comment that I can just remove this file without breaking any Umbraco functionality?

    Thanks again for your quick replies, just what I needed!

    Cheers,

    Chris

  • Aaron Powell 1708 posts 3046 karma points c-trib
    May 27, 2010 @ 05:26
    Aaron Powell
    1

    Yes, you can remove it without any problem, it doesn't do anything vital (in fact, I'm pretty sure what it does is ignored through out the site anyway).

    App_global.asax.dll I've only come across in legacy site upgrades, or sites without a global.asax file.

    If you want to work with the HttpApplication you can only have 1 instance of the class and it's best practice to have a global.asax file so you can found the pointer to that instance.

    Also, don't put your class in the App_Code folder, this causes the type to be compiled before the application states into a dynamic assembly (ie - one in your ASP.NET Temporary Cache folder). It's then really hard to debug (app startup compiler errors are what you get) and you can't use it as a referenced assembly.

  • moseeds 13 posts 29 karma points
    May 27, 2010 @ 19:20
    moseeds
    0

    Hi Chris,

     

    How strange, I have the original App_global.asax.dll in my /bin folder along with my own global_asax compiled code in my own project dll also in /bin. Have I missed something!?

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 19, 2011 @ 10:07
    Jonas Eriksson
    0

    Does someone has this working in Juno? I'm not getting the Application_Start to run for me. (I removed the app_global.asax.dll) what am I missing? hmm...

    public class RavenDbInit : umbraco.Global
        {
            protected override void Application_Start(object sender, EventArgs e)
            {
                base.Application_Start(sender, e);
            Log.Add(LogTypes.Custom,-1,"Application start");
            }
        }
  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jan 19, 2011 @ 15:23
    Ismail Mayat
    1

    Jonas,

    I remember raising this on codeplex and was told 452 will have ability to override which is also there in juno and you are trying but i recall there was a reason why this wont work but cant remember try reflecting in umbraco.Global or view the umbraco source directly as a solution try http://our.umbraco.org/forum/developers/extending-umbraco/10564-Accessing-globalasax-events- Matts comment of inherting from ApplicationBase as that effectively acts as application_start

    Regards


    Ismail

  • Jonas Eriksson 930 posts 1825 karma points
    Jan 19, 2011 @ 15:59
    Jonas Eriksson
    0

    Thanks Ismail & Matt, worked like a charm. Cheers!

  • Ken Schnell 35 posts 147 karma points
    Aug 05, 2020 @ 18:50
    Ken Schnell
    0

    For those looking for Version > 8 information you might want to visit

    Subscribing to Events

Please Sign in or register to post replies

Write your reply to:

Draft