Asp.net MVC MiniProfiler "Request is not available in this context"
Asked Answered
M

1

5

I am trying to use MiniProfiler for my MVC application which is using Oracle DB. Here is my global.asax .

protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();    
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);            
         MiniProfiler.Start(); //or any number of other checks, up to you 

    }
    protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        DevExpressHelper.Theme = "Metropolis";
        MiniProfiler.Stop(); //stop as early as you can, even earlier with MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);

    }

When application starts i am getting :

"Request is not available in this context"

Malodorous answered 6/5, 2014 at 11:22 Comment(0)
S
13

You are getting this error because you are running MiniProfiler.Start() in the wrong place. You need to run MiniProfiler.Start() as part of Application_BeginRequest. Move it to this function and it should work.

When you run it as part of Application_Start it fails, because it is trying to access HttpContext.Current, which is not accessible in Application_Start.

In the context of MiniProfiler, Application_Start is a good place to make any global MiniProfiler.Setting customizations that you would like to have in place for all requests.

Scuta answered 7/5, 2014 at 5:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.