Change Global.asax via NuGet package?

I create a NuGet package and wondered if there is a way to change the Global.asax of the target site? I would like to add one line to Application_Start (and create Global.asax if it is not there). Is it possible? How will updates work?

+7
source share
1 answer

The recommended approach is not to modify the Global.asax file of the host application. Instead, you can use WebActivator and add a separate file to the project. Take a look, for example, at Ninject.MVC3 NuGet, which does just that.

For example, when you install your NuGet, you can simply add the following file ~/App_Start/MyNuGetAppStart.cs :

 [assembly: WebActivator.PreApplicationStartMethod(typeof(SomeNamespace.AppStart), "Start")] namespace SomeNamespace { public static class AppStart { /// <summary> /// Will run when the application is starting (same as Application_Start) /// </summary> public static void Start() { ... put your initialization code here } } } 

This is a much more unobtrusive way to add custom code when the application starts, rather than messing around with the Global.asax file that the user may already have configured.

+11
source

All Articles