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



我正试图使用MiniProfiler为我的MVC应用程序使用Oracle DB。这是我的全球。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);
    }

当应用程序启动时,我得到:

"请求在此上下文中不可用"

你得到这个错误,因为你在错误的地方运行MiniProfiler.Start()。您需要将MiniProfiler.Start()作为Application_BeginRequest的一部分运行。把它移到这个函数中,它应该可以工作了。

当您将其作为Application_Start的一部分运行时,它失败了,因为它试图访问HttpContext.Current,而Application_Start无法访问。

在MiniProfiler的上下文中,Application_Start是对所有请求进行全局MiniProfiler.Setting自定义的好地方。

相关内容

最新更新