Kal*_*exx 12 c# asp.net-mvc mvc-mini-profiler
我试图在我的Asp.Net MVC应用程序中使用MvcMiniProfiler.我安装了最新的NuGet包,并从wiki页面添加到所有的代码Application_BeginRequest(),Application_AuthenticateRequest()并在我的观点.
加载页面后,所有迷你探查器的javascript文件都被包含在内并从服务器上正确下载,但当它尝试获取结果时Chrome显示:
GET http://localhost:59269/mini-profiler-results?id=59924d7f-98ba-40fe-9c4a-6a163f7c9b08&popup=1 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
我认为这是由于没有设置MVC的路由允许/mini-profiler-results但是我找不到办法做到这一点.查看Google代码页,他们Global.asax.cs的示例应用程序的文件经历了多次更改,一次使用MvcMiniProfiler.MiniProfiler.RegisterRoutes(),第二次使用MvcMiniProfiler.MiniProfiler.Init(),第三种样式不执行任何操作.前面提到的两个函数不存在,所以我假设它们已被逐步淘汰.
在这一点上,我不确定如何修复此错误并在我的应用程序中使用分析器.有任何想法吗?
我的Global.Asax.cs文件如下所示:
public class Global : System.Web.HttpApplication
{
protected void Application_BeginRequest()
{
MvcMiniProfiler.MiniProfiler.Start();
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
// Only show profiling to admins
if (!Roles.IsUserInRole(Constants.AdminRole))
MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);
}
protected void Application_Start(object sender, EventArgs e)
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.MapRoute(
"Default",
// Route name
"{controller}/{action}/{id}",
// URL with parameters
new { controller = "Home", action = "Index", id = "" }
// Parameter defaults
);
}
}
Run Code Online (Sandbox Code Playgroud)
Mar*_*ell 22
RegisterRoutes()现在,静态构造函数会自动调用该方法(并使用适当的写锁等),而第一次调用时应调用该方法MiniProfiler.Start().这应该将路由注入路由表.
因此,除非您在第一次触摸探查器后在某个时刻明确清除路由表,否则它应该(所有条件相同)都可以工作.
我想知道这是不是安全的事情.例如,您运行的是哪个版本的IIS?在某些配置(特别是IIS6)中,路径需要由服务器识别,或者您需要启用通配符.如果是这种情况,请告诉我 - 也许我们可以实施某种后备路线到ashx或其他东西.
更新:问题是您没有在查询结束时保存结果; 存在短期和长期存储,并且都提供了默认实现 - 您需要做的就是:
protected void Application_EndRequest(object sender, EventArgs e)
{
MiniProfiler.Stop(discardResults: !IsAnAdmin());
}
Run Code Online (Sandbox Code Playgroud)
更新更新:您可能还需要添加以下web.config中,在<system.webServer>,<handlers>部分:
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*"
type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified"
preCondition="integratedMode" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3736 次 |
| 最近记录: |