1

I have searched the web for over one day but I did not find anything I need.

I am developing an IIS web application with HttpHandlers and HttpModules. I need to initialize the application on first run (applying configuration). But I do not want to use global.asax.cs because I do not want implementations having a global.asax file in their folder (a web.config at most).

How do I run some code when the application pool is being initialized?

1 Answer 1

1

You could use the assembly level attribute PreApplicationStartMethodAttribute to have your startup code run early in the ASP.NET pipeline.

namespace MyWebService
{
     public class MyHttpHandler: IHttpHandler, IDisposable
     {

            public static void StartUp()
            {
                //Application Startup Code;
            }

            public void ProcessRequest(HttpContext context)
            {
                    //Do Something 
            }

            public bool IsReusable { get; private set; }

            public void Dispose(){};

            }
        }
    }
}

And add the attribute to your AssemblyInfo.cs

[assembly: PreApplicationStartMethod(typeof(MyWebService.MyHttpHandler), "StartUp")] 

For more info on PreApplicationStartMethod : https://msdn.microsoft.com/en-us/library/system.web.preapplicationstartmethodattribute

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.