我正在尝试在我的 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)
我认为这是由于没有使用 MVC 设置路由以允许/mini-profiler-results
但我找不到这样做的方法。查看 Google 代码页,他们Global.asax.cs
的示例应用程序文件经历了几次更改,一次 using MvcMiniProfiler.MiniProfiler.RegisterRoutes()
,第二次 using 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
);
}
}