MiniProfiler with Web.API 2; Is there a global magic request context object?

I am trying to set up MiniProfiler on my api website and having difficulty getting MiniProfiler.Currentto work.

I followed the directions to miniprofiler.com and had the following in global.asax:

protected void Application_Start()
{
  MiniProfilerEF6.Initialize();
  // other setup
}
protected void Application_BeginRequest() {
  // need to start one here in order to render out the UI
  MiniProfiler.Start();
}
protected void Application_EndRequest() {
  MiniProfiler.Stop();
}

In this case, the default WebRequestProfilerProvider is used , which saves the actual profile object in HttpContext.Current.Items.

When I request MiniProfiler.Current, it looks like HttpContext.Current.

When I make a request to one of my web api urls:

  • Application_BeginRequest creates a profiler, saving it in HttpContext.Current
  • in web api MessageHandleri seeHttpContext.Current
  • apu in web- IActionFilter, HttpContext.Currentnow has a value of null, and my attempt MiniProfiler.Current.Step("controller:action")fails
  • EF, , , miniprofiler MiniProfiler.Current, HttpContext.Current, null.
  • Application_EndRequest , HttpContext.Current , , .

, IProfileProvider, - , HttpContext.Current, , .

, , . :

  • IProfileProvider - ; MVC Web API IProfileProvider
  • web api RequestContext.Properties, HttpContext , , IProfileProvider ; HttpContext A, HttpContexts
  • - threadstorage - , async/
  • Ninject InRequestScope, InRequestScope, , web api 2.1,
  • , HttpRequestMessage.Properties - HttpContext.Current.Items, , IProfileProvider - , , , HttpRequestMessage. MiniProfiler.Current , , IProfileProvider - HttpRequestMessage? .

. .

+4

Source: https://habr.com/ru/post/1537818/


All Articles