MvcMiniProfiler 结果请求在 Asp.Net MVC 应用程序中给出 404
我正在尝试在我的 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 设置路由来允许 < code>/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
);
}
}
I am trying to use the MvcMiniProfiler in my Asp.Net MVC application. I installed the latest NuGet package and added all the code from the wiki page into Application_BeginRequest()
, Application_AuthenticateRequest()
and in my view.
Upon loading the page, all of the mini profiler's javascript files are being included and correctly downloaded from the server, but when it attempts to get the results Chrome shows:
GET http://localhost:59269/mini-profiler-results?id=59924d7f-98ba-40fe-9c4a-6a163f7c9b08&popup=1 404 (Not Found)
I assume this is due to no routes being setup with MVC to allow for the /mini-profiler-results
however I cannot find a way to do that. Looking at the Google code page, their Global.asax.cs
file of their sample app has gone through several changes, with one time using MvcMiniProfiler.MiniProfiler.RegisterRoutes()
, a second using MvcMiniProfiler.MiniProfiler.Init()
, and a third style which does nothing of the sort. The previously mentioned two functions do not exist, so I assume they have been phased out.
At this point I'm unsure of how I can fix this error and use the profiler in my app. Any ideas?
My Global.Asax.cs file looks like:
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
);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,静态构造函数会自动调用
RegisterRoutes()
方法(并使用适当的写锁等),而该构造函数应在您首次调用MiniProfiler.Start()< 时依次调用/代码>。这应该将路由注入路由表中。
因此,除非您在第一次接触探查器之后的某个时刻明确清除路由表,否则它应该(在所有条件相同的情况下)工作。
我想知道这是否是一个安全问题。例如,您运行的是哪个版本的 IIS?在某些配置中(特别是 IIS6),路径需要被服务器识别,或者您需要启用通配符。如果是这种情况,请告诉我 - 也许我们可以实现某种到 ashx 或其他东西的后备路由。
更新:问题是您没有在查询结束时保存结果;有短期和长期存储,并且都提供了默认实现 - 您所需要做的就是:
更新 update:您可能还需要将以下内容添加到 web.config,在
< ;system.webServer>
,
部分:The
RegisterRoutes()
method is now called automatically (and with appropriate write-locks, etc) by the static constructor, which should in turn be called when you first callMiniProfiler.Start()
. This should inject the routes into the route-table.So unless you are explicitly clearing the route-table at some point after you have first touched the profiler, it should (all things being equal) work.
I wonder if this is a security thing. For example, which version of IIS are you running with? In some configs (IIS6 in particular) the path needs to be recognised by the server, or you need to enable a wildcard. If this is the case, please let me know - maybe we can implement some kind of fallback route to an ashx or something.
Update: the problem is that you aren't saving the results at the end of the query; there is both short-term and long-term storage, and both have default implementations provided - all you need to do is something like:
Update update: you may also need to add the following to web.config, in the
<system.webServer>
,<handlers>
section: