U4-1173 - Custom global.asax doesn't work any more in 4.10.0

Created by Sebastiaan Janssen 11 Nov 2012, 10:56:02 Updated by Mike Chambers 20 Nov 2012, 16:54:43

I've implemented a custom global.asax in 4.9.x and it's not working any more.

Comments

Sebastiaan Janssen 11 Nov 2012, 10:56:05

We have a new global.asax class that runs the new bootstrapper for Umbraco so if anyone has a custom global.asax class they will need to recompile and inherit from the new class.


Sebastiaan Janssen 11 Nov 2012, 12:52:11

You can use the new IApplicationEventHandler to trigger events in the new bootstrapper (there's no need to put code in all three of the methods, leaving them blank is perfectly fine):

using Umbraco.Core; using Umbraco.Web;

namespace YourNamespace { public class AppStart : IApplicationEventHandler { public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) { //your code here }

    public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext)
    {
        //your code here
    }

    public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
    {
        //your code here
    }
}

}


Mike Chambers 20 Nov 2012, 16:09:28

extending this... is this the correct way to hook up document event handlers..

by adding a constructor...

    {code}public AppStart ()
    {
        Document.New += new Document.NewEventHandler(Document_New);
    }

    void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
    { //SOME CODE }{code}


Scott Williams 20 Nov 2012, 16:22:13

I would think the best place to add that would be in the OnApplicationStarted code block.


Mike Chambers 20 Nov 2012, 16:24:13

tried that.. eg Document.New += new Document.NewEventHandler(Document_New); in the OnApplicationStarted... it never fired.


Scott Williams 20 Nov 2012, 16:36:22

I've just tested the below code in 4.10.1 and both '''Document_New''' and '''Document_New2''' fired when I created new document.

public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext) { Document.New += Document_New; Document.New += new Document.NewEventHandler(Document_New2); }

void Document_New(Document sender, NewEventArgs e)

void Document_New2(Document sender, NewEventArgs e)


Sebastiaan Janssen 20 Nov 2012, 16:38:02

Yup, works for OnApplicationStarting as well by the way.


Mike Chambers 20 Nov 2012, 16:44:02

Retested and can confirm working, not sure why I wasn't seeing it before.. Would there be a preference to having document event handlers in the started or starting method?


Sebastiaan Janssen 20 Nov 2012, 16:50:42

I'm actually not sure which one would be best, I like registering things while the app is starting so I chose that one. Not sure what the problem might've been before, could be that the dll wasn't copied into your bin folder yet? Make sure to double check next time, also to see if the code actually compiled.


Mike Chambers 20 Nov 2012, 16:54:43

Cheers guys... prob just human error...


Priority: Normal

Type: Bug

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: False

Fix Submitted:

Affected versions: 4.10.0

Due in version:

Sprint:

Story Points:

Cycle: