I have defined this class within the App_Code section of my website and I have also created it within a Class library and added the DLL to my website's BIN folder. Neither causes the ApplicationStarting event in my class to be fired.
I am using Umbraco V7.1.4
Any ideas why or even how I could debug this to see whats happening ?
Debuggers aren't 100% reliable in these kind of situations (app start-up).
Try to log something in-code so you can check that. Or create a text file in the root of your website (with C#). Maybe it does hit the method...
Thanks, I haven't had such reliability issues in the past with debugging, however I have added Log4net logging and found nothing.
I suspected that maybe Log4net was not properly started at this point, so I added a call to write to a file and it triggered an access denied message (I didn't provide a path so it tried to write it in the system32 folder) so I shall go from here and see what is going on.
I think I have the same issue since I get a 500 error whenever I try to call my API which I had working in a local Umbraco project. Did you have any success? How can I write to the Umbraco log?
Actually, it turns out that VS is able to break on my break points there. I had to start the debugger then update web.config in order to catch the application restarting in time.
ApplicationStarting not Firing
I have defined a simple class to handle the ApplicationStarting event in order to wire up a 404 handler as follows:
public class MyApplication : ApplicationEventHandler {
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {
ContentLastChanceFinderResolver.Current.SetFinder(new _404NewsFinder());
base.ApplicationStarting(umbracoApplication, applicationContext);
}
}
How did you check if the ApplicationStarting is being fired or not?
Via the Visual Studio 2013 debugger.
Debuggers aren't 100% reliable in these kind of situations (app start-up).
Try to log something in-code so you can check that. Or create a text file in the root of your website (with C#). Maybe it does hit the method...
Thanks, I haven't had such reliability issues in the past with debugging, however I have added Log4net logging and found nothing.
I suspected that maybe Log4net was not properly started at this point, so I added a call to write to a file and it triggered an access denied message (I didn't provide a path so it tried to write it in the system32 folder) so I shall go from here and see what is going on.
Thanks for the idea
I think I have the same issue since I get a 500 error whenever I try to call my API which I had working in a local Umbraco project. Did you have any success? How can I write to the Umbraco log?
John, my circumstances seem a little different in that the event really was firing, but the debugger wasnt catching it.
To get logging... I add the following "using" statements...
using log4net;
using System.Reflection;
Then I add the following declaration to my class:
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
The when I want to log anything I call:
Log.Error("My error message");
The log4net logging capabilities provided in Umbraco are great, its worth taking a read.
Thank you. Actually I had just figured out the logging. I found you can use the logger by adding
Then in your code:
I did discover that ApplicationStarting is being called even though the remote debugger in VS does not break on my break points there.
Actually, it turns out that VS is able to break on my break points there. I had to start the debugger then update web.config in order to catch the application restarting in time.
John, thats a great solution... will try that thanks.
Russell
is working on a reply...