gpt4 book ai didi

c# - MvcMiniProfiler 结果请求在 Asp.Net MVC 应用程序中给出 404

转载 作者:可可西里 更新时间:2023-11-01 08:19:21 24 4
gpt4 key购买 nike

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

加载页面后,所有迷你分析器的 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 文件经历了多次更改,其中一次使用了 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
);
}
}

最佳答案

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

因此,除非您在首次接触分析器后某个时间点明确清除路由表,否则它应该(所有条件都相同)工作。 p>

我想知道这是否是安全问题。例如,您运行的是哪个版本的 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" />

关于c# - MvcMiniProfiler 结果请求在 Asp.Net MVC 应用程序中给出 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6497180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com