Search code examples
asp.net-web-apiowinhttpcontext

How to access HttpContext.Current.Application on OWIN Startup


I need to fill HttpContext.Current.Application["Translations"] on OWIN startup, but HttpContext.Current is null there.

Should I use Application_Start() in Global.asax.cs or it is bad idea?

What alternatives do I have?


Solution

  • HttpContext is not available at start up as it cannot exist without a request. The Startup class only runs once for the application, not for each request.

    Try accessing it in the BeginRequest handler in Global.asax.cs.

    protected void Application_BeginRequest(object sender, EventArgs e) {
    
        base.Application["Translations"] = "My value here";
    
    }