MvcMiniProfiler结果请求在Asp.Net MVC应用程序中提供404

时间:2022-12-04 17:44:46

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.

我试图在我的Asp.Net MVC应用程序中使用MvcMiniProfiler。我安装了最新的NuGet包,并将维基页面中的所有代码添加到Application_BeginRequest(),Application_AuthenticateRequest()和我的视图中。

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:

加载页面后,所有迷你探查器的javascript文件都被包含在内并从服务器上正确下载,但当它尝试获取结果时Chrome显示:

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.

我假设这是因为没有设置MVC的路由以允许/ mini-profiler结果但是我找不到办法做到这一点。查看Google代码页,他们的示例应用程序的Global.asax.cs文件经历了多次更改,一次使用MvcMiniProfiler.MiniProfiler.RegisterRoutes(),第二次使用MvcMiniProfiler.MiniProfiler.Init(),第三次什么都不做的风格。前面提到的两个函数不存在,所以我假设它们已被逐步淘汰。

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:

我的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
        );
    }
}

1 个解决方案

#1


22  

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 call MiniProfiler.Start(). This should inject the routes into the route-table.

现在,静态构造函数自动调用RegisterRoutes()方法(并使用适当的写锁等),当您第一次调用MiniProfiler.Start()时,应该调用该方法。这应该将路由注入路由表。

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.

我想知道这是否是安全的事情。例如,您运行的是哪个版本的IIS?在某些配置(特别是IIS6)中,路径需要由服务器识别,或者您需要启用通配符。如果是这种情况,请告诉我 - 也许我们可以实施某种后备路线到ashx或其他东西。


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:

更新:问题是您没有在查询结束时保存结果;有短期和长期存储,并且都提供了默认实现 - 您需要做的就是:

protected void Application_EndRequest(object sender, EventArgs e)
{
    MiniProfiler.Stop(discardResults: !IsAnAdmin());
}

Update update: you may also need to add the following to web.config, in the <system.webServer>, <handlers> section:

更新更新:您可能还需要在 部分中将以下内容添加到web.config:

<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*"
    type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified"
    preCondition="integratedMode" />

#1


22  

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 call MiniProfiler.Start(). This should inject the routes into the route-table.

现在,静态构造函数自动调用RegisterRoutes()方法(并使用适当的写锁等),当您第一次调用MiniProfiler.Start()时,应该调用该方法。这应该将路由注入路由表。

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.

我想知道这是否是安全的事情。例如,您运行的是哪个版本的IIS?在某些配置(特别是IIS6)中,路径需要由服务器识别,或者您需要启用通配符。如果是这种情况,请告诉我 - 也许我们可以实施某种后备路线到ashx或其他东西。


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:

更新:问题是您没有在查询结束时保存结果;有短期和长期存储,并且都提供了默认实现 - 您需要做的就是:

protected void Application_EndRequest(object sender, EventArgs e)
{
    MiniProfiler.Stop(discardResults: !IsAnAdmin());
}

Update update: you may also need to add the following to web.config, in the <system.webServer>, <handlers> section:

更新更新:您可能还需要在 部分中将以下内容添加到web.config:

<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*"
    type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified"
    preCondition="integratedMode" />