Developer forum

Forum » Development » global.asax code

global.asax code

Karol Barkowski
Reply

Hi,

In DW10 I have access to the Startup.cs file where I can configure my whole project, use filters, middlewares, configure dependency injection containers, error handlers, generate swagger files, all that standart stuff that each and every web project needs.

And then I open DW9 projec and I cannot do any of that because there's no access to the glabal.asax file. And that file is the place where all that configuration ususally goes. And I really cannot see any single reason why.

Is there any hack/workaround around this? Maybe there's some repo where I could see the original glabal.asax code so I could just put it my project and replace the defulat one and start extending it with stuff I actually need?

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Karol

You can deploy your own version of the global.asax file - overwrite the Global.asax file with your own version and proxy into DW - this is what DW does:

using System;
using System.Web;
using Dynamicweb.Frontednd;

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Application_Start(sender, e);
    }

    void Session_Start(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Session_Start(sender, e);
    }

    void Application_BeginRequest(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Application_BeginRequest(sender, e);
    }

    void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Application_AuthenticateRequest(sender, e);
    }

    void Application_OnPreRequestHandlerExecute(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Application_OnPreRequestHandlerExecute(sender, e);
    }

    void Application_EndRequest(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Application_EndRequest(sender, e);
    }

    void Application_Error(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Application_Error(sender, e);
    }

    void Session_End(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Session_End(sender, e);
    }

    void Application_End(object sender, EventArgs e)
    {
        GlobalAsaxHandler.Application_End(sender, e);
    }
}
Votes for this answer: 1
 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Karol,

In DW9 you can also use notifications for different application lifecycle events. Dynamicweb.Notifications.Standard.Application contains several notifications which you can use.

using Dynamicweb;

namespace Dynamicweb.Examples.Notifications.Standard
{
    [Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStart)]
    public class ApplicationStartObserver : Dynamicweb.Extensibility.Notifications.NotificationSubscriber
    {
        public override void OnNotify(string notification, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
        {
            if (args == null)
                return;

            if (!(args is Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStartArgs))
                return;

            Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStartArgs item = (Dynamicweb.Notifications.Standard.Application.AfterDynamicwebStartArgs)args;

            //Add code here

        }
    }
}

Alternatively, you can register an implementation of IHttpModule.

/Morten

 
Karol Barkowski
Reply

That is a very important piece of information you just gave me here.

Thank you.

 

You must be logged in to post in the forum