public class MyApp : HttpApplication { protected void Application_Start(object sender, EventArgs e) { // Code to run on application startup } }
public class MyApp : HttpApplication { protected void Application_BeginRequest(object sender, EventArgs e) { // Get the current request object HttpRequest httpRequest = Context.Request; // Get the current response object HttpResponse httpResponse = Context.Response; // Write a custom response header httpResponse.AddHeader("X-Custom-Header", "Hello World!"); } }
public class MyApp : HttpApplication { protected void Application_Error(object sender, EventArgs e) { // Get the last error that occurred Exception exception = Server.GetLastError(); // Log the error to a file, database, etc. Log.Error(exception); // Display a friendly error page to the user Server.Transfer("~/error.aspx"); } }The HttpApplication class is part of the System.Web.dll package library, which is included in the .NET Framework.