От: | QrystaL | ||
Дата: | 22.04.14 18:02 | ||
Оценка: | 136 (4) +1 |
PreApplicationStartMethodAttribute
This new attribute allows you to have code run way early in the ASP.NET pipeline as an application starts up. I mean way early, even before Application_Start. This happens to also be before code in your App_code folder (assuming you have any code in there) has been compiled. To use this attribute, create a class library and add this attribute as an assembly level attribute. A common place to add this would be in the AssemblyInfo.cs class within the Properties folder. Here’s an example:
[assembly: PreApplicationStartMethod(typeof(SomeClassLib.Initializer), "Initialize")]
Note that I specified a type and a method. That method needs to be a public static void method with no arguments. Now, any ASP.NET website that references this assembly will call the Initialize method when the application is about to start, giving this method a chance to do perform some early initialization.
public static class Initializer { public static void Initialize() { // Whatever can we do here? } }