1

我想将一瞥诊断工具添加到我的 mvc4 hot-towel 项目中。

我正在按照说明http://nuget.org/packages/Glimpse.Mvc4/并在我的项目中安装 glimpse 的 mvc4 nuget 包。

它正在正确安装并获得依赖关系并更新 web.config,如下所示。

<httpModules>
  <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
</httpModules>
<httpHandlers>
  <add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
</httpHandlers>

<handlers>
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
  <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
  <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
  <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<modules>
  <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
</modules>

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<!-- If you are having issues with Glimpse, please include this. It will help us figure out whats going on. 
  <logging level="Trace" />-->
<!-- Want to use Glimpse on a remote server? Ignore the LocalPolicy by removing this comment.
  <runtimePolicies>
    <ignoredTypes>
      <add type="Glimpse.AspNet.Policy.LocalPolicy, Glimpse.AspNet"/>
    </ignoredTypes>
  </runtimePolicies>-->

但是,当我运行项目并输入诸如http://mylocalurl.com/glimpse.axd之类的 url 时。它没有找到 axd 文件,所以我无法启用一瞥。

PS我已经定义了加载热毛巾模板索引页面的自定义路径。

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Load", action = "Index", id = UrlParameter.Optional }
        );
    }
4

2 回答 2

3

找不到 Glimpse.axd 的原因是配置路由的顺序。

如果您安装RouteDebugger NuGet 包,您会看到还有另一个路由处理 Glimpse.axd 请求,即由 Hot Towel 模板安装的路由,可以App_Start在类的文件夹中找到HotTowelRouteConfig

using System.Web.Mvc;

[assembly: WebActivator.PreApplicationStartMethod(
    typeof(throwaway.App_Start.HotTowelRouteConfig), "RegisterHotTowelPreStart", Order = 2)]

namespace throwaway.App_Start {
  ///<summary>
  /// Inserts the HotTowel SPA sample view controller to the front of all MVC routes
  /// so that the HotTowel SPA sample becomes the default page.
  ///</summary>
  ///<remarks>
  /// This class is discovered and run during startup
  /// http://blogs.msdn.com/b/davidebb/archive/2010/10/11/light-up-your-nupacks-with-startup-code-and-webactivator.aspx
  ///</remarks>
  public static class HotTowelRouteConfig {

    public static void RegisterHotTowelPreStart() {

      // Preempt standard default MVC page routing to go to HotTowel Sample
      System.Web.Routing.RouteTable.Routes.MapRoute(
          name: "HotTowelMvc",
          url: "{controller}/{action}/{id}",
          defaults: new
          {
              controller = "HotTowel",
              action = "Index",
              id = UrlParameter.Optional
          }
      );
    }
  }
}

并且由于此路由将在执行之前RouteConfig.RegisterRoutes添加(由于使用WebActivator),它将处理 Glimpse.axd 的请求,因为该路由具有每个路由参数的默认值,因此将匹配 Glimpse.axd 请求。

您可以通过删除来解决这个问题,HotTowelRouteConfig但是您必须明确地访问示例 url http://mylocalurl.com/HotTowel/Index,或者您WebActivatorHotTowelRouteConfig

[assembly: WebActivator.PreApplicationStartMethod(
    typeof(throwaway.App_Start.HotTowelRouteConfig), "RegisterHotTowelPreStart", Order = 2)]

RouteConfig.RegisterRoutes并在调用HotTowelRouteConfig.RegisterHotTowelPreStart()后通过调用显式注册路由routes.IgnoreRoute("{resource}.axd/{*pathInfo}");,默认情况下您仍将拥有该示例,并且 Glimpse.axd 将按预期处理。

无论哪种方式,这两个选项都涉及删除或更改由 HotTowel NuGet 包管理的文件,因此也许应该将示例放入其自己的 NuGet 包中(例如,您不想将示例投入生产)

于 2013-06-07T12:45:08.537 回答
1

签入Hot Towel GitHub 存储库的最新源代码处理这个略有不同。

在函数HotTowelRouteConfigRegisterHotTowlPreStart改为:

public static void RegisterHotTowelPreStart() {

  // Ignore requests to .axd HttpHandlers
  System.Web.Routing.RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  // Preempt standard default MVC page routing to go to HotTowel Sample
  System.Web.Routing.RouteTable.Routes.MapRoute(
      name: "HotTowelMvc",
      url: "{controller}/{action}/{id}",
      defaults: new
      {
          controller = "HotTowel",
          action = "Index",
          id = UrlParameter.Optional
      }
  );

这允许axd包括Glimpse.axd工作,通过排除它们被样本处理。

于 2013-08-06T12:44:53.820 回答