MVC Mini Profiler 不尊重应用程序的路径

发布于 2024-11-15 00:42:32 字数 2862 浏览 4 评论 0原文

我已按照项目页面中的说明设置了 MVC Mini Profiler,其中包括确实被写在页面上。

问题是,我的应用程序位于 http://localhost:8080/web,分析器编写的标记如下所示:

<link rel="stylesheet/less" type="text/css" href="/mini-profiler-includes.less?v=2.0.4177.17902">
<script type="text/javascript" src="/mini-profiler-includes.js?v=2.0.4177.17902"></script>
<script type="text/javascript"> jQuery(function() { MiniProfiler.init({ id:'fb4dc30e-c1aa-4be6-902c-ef2812dd1fe2', renderDirection:'left' }); } ); </script>

这些当然都会给出 404 错误,但如果我导航到 < code>/web/mini-profiler-includes.less?,它加载得很好。

创建该字符串的源代码可以在此处找到:

// MiniProfilerHandler.cs
/// <summary>
/// Understands how to route and respond to MiniProfiler UI urls.
/// </summary>

public class MiniProfilerHandler : IRouteHandler, IHttpHandler
{
    internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition? position = null, bool showTrivial = false, bool showTimeWithChildren = false)
    {
        const string format =
            @"<link rel=""stylesheet/less"" type=""text/css"" href=""{0}mini-profiler-includes.less?v={1}"">
            <script type=""text/javascript"" src=""{0}mini-profiler-includes.js?v={1}""></script>
            <script type=""text/javascript""> jQuery(function() {{ MiniProfiler.init({{ id:'{2}', path:'{0}', renderDirection:'{3}', showTrivial: {4}, showChildrenTime: {5} }}); }} ); </script>";

        var pos = position ?? (MiniProfiler.Settings.RenderPopupButtonOnRight ? RenderPosition.Right : RenderPosition.Left);

        var result = profiler == null ? "" : string.Format(format,
                                                       EnsureEndingSlash(HttpContext.Current.Request.ApplicationPath),
                                                       MiniProfiler.Settings.Version,
                                                       profiler.Id,
                                                       pos.ToString().ToLower(),
                                                       showTrivial ? "true" : "false",
                                                       showTimeWithChildren ? "true" : "false");

        return new HtmlString(result);
    }

    // rest of the code
}

为什么 Request.ApplicationPath 没有返回我的应用程序的路径?我是否做错了什么,或者我应该在 mvc-mini-profiler 页面上提交问题?

编辑:为了让事情变得更奇怪,我在 MiniProfiler.RenderIncludes() 调用上放置了一个断点,并检查了 HttpContext.Current.Request 的值。那时的ApplicationPath就是“/web”!非常神秘。

编辑2:看起来他们可能在最新版本中添加了对虚拟路径的支持(2小时前:)),并且NuGet包(这就是我安装它的方式)并不完全是最新的。正在调查...

I've got the MVC Mini Profiler set up as described on its project page, and the includes are indeed being written on the page.

Problem is, my application sits at http://localhost:8080/web, and the markup written by the profiler includes looks like this:

<link rel="stylesheet/less" type="text/css" href="/mini-profiler-includes.less?v=2.0.4177.17902">
<script type="text/javascript" src="/mini-profiler-includes.js?v=2.0.4177.17902"></script>
<script type="text/javascript"> jQuery(function() { MiniProfiler.init({ id:'fb4dc30e-c1aa-4be6-902c-ef2812dd1fe2', renderDirection:'left' }); } ); </script>

These all of course give 404 errors, but if I navigate to /web/mini-profiler-includes.less?, it loads fine.

The source that creates that string can be found here:

// MiniProfilerHandler.cs
/// <summary>
/// Understands how to route and respond to MiniProfiler UI urls.
/// </summary>

public class MiniProfilerHandler : IRouteHandler, IHttpHandler
{
    internal static HtmlString RenderIncludes(MiniProfiler profiler, RenderPosition? position = null, bool showTrivial = false, bool showTimeWithChildren = false)
    {
        const string format =
            @"<link rel=""stylesheet/less"" type=""text/css"" href=""{0}mini-profiler-includes.less?v={1}"">
            <script type=""text/javascript"" src=""{0}mini-profiler-includes.js?v={1}""></script>
            <script type=""text/javascript""> jQuery(function() {{ MiniProfiler.init({{ id:'{2}', path:'{0}', renderDirection:'{3}', showTrivial: {4}, showChildrenTime: {5} }}); }} ); </script>";

        var pos = position ?? (MiniProfiler.Settings.RenderPopupButtonOnRight ? RenderPosition.Right : RenderPosition.Left);

        var result = profiler == null ? "" : string.Format(format,
                                                       EnsureEndingSlash(HttpContext.Current.Request.ApplicationPath),
                                                       MiniProfiler.Settings.Version,
                                                       profiler.Id,
                                                       pos.ToString().ToLower(),
                                                       showTrivial ? "true" : "false",
                                                       showTimeWithChildren ? "true" : "false");

        return new HtmlString(result);
    }

    // rest of the code
}

Why isn't Request.ApplicationPath returning my application's path? Am I doing something wrong, or should I file an issue on the mvc-mini-profiler page?

EDIT: To make things even weirder, I put a breakpoint on the MiniProfiler.RenderIncludes() call, and checked what the value of HttpContext.Current.Request.ApplicationPath was at that moment, and it was "/web"! Very mysterious.

EDIT 2: Looks like they may have added support for virtual paths in the latest version (2 hours ago :)), and the NuGet package (which is how I installed it) is not completely up to date. Investigating...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姜生凉生 2024-11-22 00:42:33

提取最新的源代码(此提交是最近在写这篇文章时),构建项目,获取 DLL 并引用它而不是使用该项目的 NuGet 包解决了该问题。

编辑:截至目前,NuGet 包现已与最新提交保持同步,所以 NuGet 就可以了!

Pulling the latest source (this commit being the most recent at time of this post), building the project, grabbing the DLL and referencing that instead of using the project's NuGet package fixed the problem.

EDIT: As of right now, the NuGet package is now up to date with the latest commit, so NuGet away!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文