我正在尝试在我的MvcMiniProfiler MVC应用程序中使用Asp.Net。我安装了最新的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的路由,但是我无法找到这样的方法。查看谷歌代码页面,他们的示例应用程序的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
);
}
}发布于 2011-06-27 18:54:48
RegisterRoutes()方法现在由静态构造函数自动调用(以及适当的写锁等),当您第一次调用MiniProfiler.Start()时应该调用该构造函数。这应该将路径注入路由表中。
因此,除非您在第一次触摸分析器之后的某个时候显式地清除路由表,否则它应该(在所有条件相同的情况下)工作。
我想知道这是不是安全问题。例如,使用哪个版本的IIS运行?在某些信任(特别是IIS6)中,路径需要被服务器识别,或者您需要启用通配符。如果是这样的话,请让我知道-也许我们可以实现某种形式的退路到一个ashx或其他什么。
更新:问题是您没有在查询结束时保存结果;有短期和长期存储,而且都提供了默认实现--您所需要做的就是:
protected void Application_EndRequest(object sender, EventArgs e)
{
MiniProfiler.Stop(discardResults: !IsAnAdmin());
}更新更新:您还可能需要在web.config中的<system.webServer>,<handlers>部分中添加以下内容:
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*"
type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified"
preCondition="integratedMode" />https://stackoverflow.com/questions/6497180
复制相似问题