Running an ASP.NET Application Without Using Global.asax

I am developing a plugin as a website app. Due to the requirements, he will live along the same physical path and the same application pool as the main website on which I do not have the source code. Thus, they both have the same Web.config and some other dependencies.

I need to install a license for third-party dependencies when the application starts, but I do not have access to the code for Global.asax, because this code belongs to another company.

So, is there an alternative way to add events to Application Start without involving Global.asax or is it the only solution to inherit / extend the current Global.asax?

+4
source share
2 answers

You can use HTTPModule:

public class MyModule : IHttpModule { #region IHttpModule Members public void Dispose() { } public void Init(HttpApplication context) { ... } #endregion } 

web.config

 <httpModules> <add name="MyModule" type="MyNamespace.MyModule, MyAssembly" /> </httpModules> 
+9
source

You can use WebActivator if you know that your target projects will be .NET 4.0 or higher.

https://github.com/davidebbo/WebActivator

 [assembly: WebActivatorEx.PostApplicationStartMethod(typeof(Bootstrapper), "Start")] public class Bootstrapper { public static void Start() { // Put everything in motion here } } 

Please note that you also have the option to run before or after the Global.asax Application_Start () function - this example starts later.

+2
source

All Articles