The global.asax.cs is compiled into a dll App_global_asax.dll which is shipped with umbraco
Below is the global.asax.cs from the 4.0.2.1 release. You can see its almost empty. (i removed all code commented out). The solution is to delete App_global.asax.dll in your umbraco distribution and make your own global.asax.cs. I did not test this myselve, but I was confronted with this today when I tried to make log4net working on a test server (eventually that log4net can also be initiated by a HttpModule). The following blog of Ismael also states that the App_global.asax.dll may be deleted from your bin directory.
A better solution is that in umbraco the events in the global.asax.cs can be handled by your own code. That is something the core-team might think about :-)
Nico
using System; using System.Web; using System.Threading;
using umbraco.BusinessLogic; using umbraco.BusinessLogic.Actions; using umbraco.cms.businesslogic.datatype.controls; using umbraco.cms.businesslogic.stat;
namespace umbraco { /// <summary> /// Summary description for Global. /// </summary> public class Global : HttpApplication { protected Timer publishingTimer; protected Timer pingTimer;
Well yes thank you ;-) - I know it's being logged already - I just inserted that line to see if MY application_start code was being triggered (which it is not).
I wan't to start a timer which gathers performance parameters from the server at regular intervals. I have implemented this at a standard asp.net application which works beautifully - but Umbraco sites are a world apart...
I have tried all kinds of techniques (from this forum) to catch the application_start but to no avail - I have tried overriding the umbraco.global, applicationBase, system.Web.HttpApplication but nothing seems to work...
(some of the methods are theroretical I suspect - and not tried out) - so have anyone actually gotten this to work in umbraco 4.7 and how?
Alright, did you remember to actually delete the existing App_global.asax.dll and have you put your own dll in the bin folder to replace the functionality? Is there no actual global.asax file still inheriting from umbraco.Global?
Maybe add a global.asax that inherits from MyGlobalEvents (add your namespace before that if you have one).
I've just tried with an older version of Umbraco and it looks like this never actually worked anyway. I can't even find where the App_Global.asax.dll is generated from the umbraco source. I still get the default "application has started" message in the log, even after deleting the dll.
' the class MUST also be added to the web.config under "configuration", "system.webServer", "modules" to work Public Class MyGlobalEvents Implements IHttpModule
Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init Log.Add(LogTypes.Debug, -1, "Vi har kaldt application INIT by IHttpModule") If IsNothing(TV2BGlobal.appglobalObjConnectionPerfCounter) Then TV2BGlobal.appglobalObjConnectionPerfCounter = New TV2BGlobal.UserStatistik End If End Sub
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose End Sub End Class
IMPORTANT: and added this to the web.config (newTV2Bornholm is the namespace) the place where this must be added is different depending upon your IIs version - mine is 7 in integrated mode (see this for more info: http://msdn.microsoft.com/en-us/library/ms227673.aspx):
However the INIT seems to fires several times during the lifetime of the application - so I needed to limit the number of instances of my global stat (which I only want ONE of for the entire app regardless of number of users and other variables)
Well, I managed to do it now by using visual studio's add dialog and choosing global.asax, this gives you a default global.asax.
But I would really go the route that Aaron is suggesting, create an httpModule, as an example look at umbraco's own umbraco.presentation.requestModule. Don't forget to add it to the web.config and you're good to go. And you can still upgrade Umbraco without worries.
Extending Global.asax
hello all,
I need to extend Application_Start, Application_End, Session_Start and Session_End methods from Global.asax.
I have seen several posts regarding the extention these methods, in this post:
http://our.umbraco.org/forum/developers/extending-umbraco/2225-Need-to-access-events-in-the-global?p=0
the presented solution is through the use of IHttpModules, however for the method I want it is not possible.
Other presented solution is by extending the class "umbraco.Global" and add it to the App_Code as presented in the post:
http://forum.umbraco.org/yaf_postst1702_Possible-to-override-ApplicationStart--ApplicationError.aspx
however I was not able to point to this class since there is no global.asax file, is there any way to point to it?
how should i extend the presented methods?
thanks in advance,
Ricardo
Hi Ricard, I am also working on csla membership with umbraco and having similar difficulties trying to extend Application_Start
but having a go.. let us know if you make progress.
Thanks
Digby
Hello Digby,
I made a temporary solution that consists in putting the desired Application_Start code in the Init() method of an HttpModule that you can add.
To add an HttpModule you can check this:
http://msdn.microsoft.com/en-us/library/ms227673%28VS.80%29.aspx
I made this since the Init() is executed more or less the same times as the Application_Start()
hope it helps,
let me know if you have any other solution,
Regards,
Ricardo
The global.asax.cs is compiled into a dll App_global_asax.dll which is shipped with umbraco
Below is the global.asax.cs from the 4.0.2.1 release. You can see its almost empty. (i removed all code commented out). The solution is to delete App_global.asax.dll in your umbraco distribution and make your own global.asax.cs. I did not test this myselve, but I was confronted with this today when I tried to make log4net working on a test server (eventually that log4net can also be initiated by a HttpModule). The following blog of Ismael also states that the App_global.asax.dll may be deleted from your bin directory.
A better solution is that in umbraco the events in the global.asax.cs can be handled by your own code. That is something the core-team might think about :-)
Nico
Just make your class inherit from the umbraco.Global, that should work.
Alternative create a HttpHander (inherit IHttpHandler) and then you have the request life cycle at your finger tips
@slace: can you give me an example on how to override the Application_start by inheriting unbraco.Global?
You should be able to do:
But really, you're better off writing your own HttpHandler, it's much more portable that way.
@slace
tried the above - but stille nothing happens (no log entry is written) - has the umbraco functionality changed - I'm on 4.7RC
Public Class MyGlobalEvents
Inherits umbraco.Global
Protected Overrides Sub Application_Start(ByVal sender As Object, ByVal e As System.EventArgs)
Log.Add(LogTypes.Debug, -1, "Vi har kaldt application START by umbraco.global")
MyBase.Application_Start(sender, e)
End Sub
end Class
What is it that you're trying to do, log the application start? Don't bother, it's already being logged.. This is one such entry:
As slace says, much better to do what you're trying to do using a HttpHandler or HttpModule.
Well yes thank you ;-) - I know it's being logged already - I just inserted that line to see if MY application_start code was being triggered (which it is not).
I wan't to start a timer which gathers performance parameters from the server at regular intervals. I have implemented this at a standard asp.net application which works beautifully - but Umbraco sites are a world apart...
I have tried all kinds of techniques (from this forum) to catch the application_start but to no avail - I have tried overriding the umbraco.global, applicationBase, system.Web.HttpApplication but nothing seems to work...
(some of the methods are theroretical I suspect - and not tried out) - so have anyone actually gotten this to work in umbraco 4.7 and how?
Alright, did you remember to actually delete the existing App_global.asax.dll and have you put your own dll in the bin folder to replace the functionality? Is there no actual global.asax file still inheriting from umbraco.Global?
Maybe add a global.asax that inherits from MyGlobalEvents (add your namespace before that if you have one).
The implementation hasn't changed much in 4.7, it's even less code then it was before.
Yes have deleted app_global.asax.dll and global.asax.cs (and global.asx.vb) from the app_code
I am copying my own NewTV2Bornholm.dll to the bin folder (using post build events in visual studio) this dll contains all my user controls and classes
I will look into the sourcecode you linked to .... Umbraco Shall Not Beat Me :-D
@Sebastiaan
just noticed that I don't have the log entry from the application_end in your quoted source code in my log either....
something strange is going on (or is that because i've deleted the app_global.asax.dll)
I've just tried with an older version of Umbraco and it looks like this never actually worked anyway. I can't even find where the App_Global.asax.dll is generated from the umbraco source. I still get the default "application has started" message in the log, even after deleting the dll.
Sorry that I can't be of more help!
Did you change the inherits attribute in your global.asax?
Umbraco has a class inheriting HttpApplication, umbraco.Global, which it tried to run by default.
But yes, I've seen a number of issues trying to override global.asax, you're better off creating a HttpModule to do what you need
All Right success at last:
Created a httpModule:
' the class MUST also be added to the web.config under "configuration", "system.webServer", "modules" to work
Public Class MyGlobalEvents Implements IHttpModule
Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init
Log.Add(LogTypes.Debug, -1, "Vi har kaldt application INIT by IHttpModule")
If IsNothing(TV2BGlobal.appglobalObjConnectionPerfCounter) Then
TV2BGlobal.appglobalObjConnectionPerfCounter = New TV2BGlobal.UserStatistik
End If
End Sub
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub
End Class
IMPORTANT: and added this to the web.config (newTV2Bornholm is the namespace) the place where this must be added is different depending upon your IIs version - mine is 7 in integrated mode (see this for more info: http://msdn.microsoft.com/en-us/library/ms227673.aspx):
and this is tested and works in umbraco 4.7.
However the INIT seems to fires several times during the lifetime of the application - so I needed to limit the number of instances of my global stat (which I only want ONE of for the entire app regardless of number of users and other variables)
Well, I managed to do it now by using visual studio's add dialog and choosing global.asax, this gives you a default global.asax.
But I would really go the route that Aaron is suggesting, create an httpModule, as an example look at umbraco's own umbraco.presentation.requestModule. Don't forget to add it to the web.config and you're good to go. And you can still upgrade Umbraco without worries.
Oh, posting at the same time! :-)
Well, I don't know about your init but Umbraco's only fires once, so have a look at the link in the previous post anyway.
For those looking for Version > 8 information you might want to visit
Subscribing to Events
is working on a reply...