Asp.net MVC MiniProfiler“请求在此上下文中不可用”
发布时间:2020-12-16 03:40:00 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试将MiniProfiler用于使用Oracle DB的MVC应用程序.这是我的global.asax. protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilt
我正在尝试将MiniProfiler用于使用Oracle DB的MVC应用程序.这是我的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); } 申请开始时,我得到:
解决方法
您收到此错误是因为您在错误的位置运行MiniProfiler.Start().您需要运行MiniProfiler.Start()作为Application_BeginRequest的一部分.将它移动到此功能,它应该工作.
当您将其作为Application_Start的一部分运行时,它将失败,因为它正在尝试访问HttpContext.Current,这在Application_Start中无法访问. 在MiniProfiler的上下文中,Application_Start是制作任何全局MiniProfiler.Setting自定义的好地方,您希望为所有请求提供这些自定义. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MV
- asp.net-mvc-3 – 用于ASP的Telerik扩展. NET MV
- asp.net – StyleCop vs ReSharper和一般编码风格
- 捆绑和分组 – MVC 6中的捆绑和分类
- asp.net – 如何验证列表框是否为空(客户端)
- asp.net-mvc – 如何将URL参数绑定到具有不同名称
- asp.net-mvc – 如何使用具有可空类型的强类型HT
- asp.net-mvc – 使用ASP.NET MVC帮助器方法设置m
- asp.net-mvc – 传统的ASP.NET Web窗体与MVC
- 在ASP.NET中使用Web API而不是Web方法有什么优势
热点阅读