Checkout the HostingEnvironment class. You might also take a look at the following article if the information you need is not present in the HostingEnvironment class. In this article the author performs the initialization logic in the Application_BeginRequest method instead of Application_Start. It uses a lock to ensure that this initialization is performed only once:
void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
HttpContext context = app.Context;
// Attempt to peform first request initialization
FirstRequestInitialization.Initialize(context);
}
and here's the FirstRequestInitialization class:
class FirstRequestInitialization
{
private static bool s_InitializedAlready = false;
private static Object s_lock = new Object();
// Initialize only on the first request
public static void Initialize(HttpContext context)
{
if (s_InitializedAlready)
{
return;
}
lock (s_lock)
{
if (s_InitializedAlready)
{
return;
}
// Perform first-request initialization here ...
s_InitializedAlready = true;
}
}
}