【问题标题】:Why Glimpse model binding tab is disabled?为什么 Glimpse 模型绑定选项卡被禁用?
【发布时间】:2013-04-17 18:10:37
【问题描述】:

我正在使用 Glimpse MVC4 1.2.0 版。

我注意到,当我在浏览器中打开 Glimpse UI 时,“模型绑定”选项卡被禁用。我看不到如何启用它。阅读Glimpse docs 表明您可以忽略标签

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
    <tabs>
        <ignoredTypes>
            <add type="{Namespace.Type, AssemblyName}"/>
        </ignoredTypes>
    </tabs>
</glimpse>

但我的 web.config 中没有这些:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <httpRuntime targetFramework="4.5" />
    <compilation debug="true" targetFramework="4.5" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <!-- Glimpse: This can be commented in to add additional data to the Trace tab when using WebForms
        <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false"/> -->
    <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>
  </system.web>
  <system.webServer>
    <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>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <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" /> -->
  </glimpse>
</configuration>

所有其他选项卡均已启用。有人可以提出禁用此选项卡的原因吗?

编辑:我注意到“会话”选项卡也被禁用。

啊,好的,在我添加了Session["Testing"] = "123" 调用后,“会话”选项卡现在已启用。尽管如此,仍然无法启用“模型绑定”选项卡。这是我在回发中的视图代码:

[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]HomeIndexViewModel viewModel)
{
    return this.View(viewModel);
}

public class MyModelBinder : IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var viewModel = new HomeIndexViewModel();

        viewModel.Name = "From model binder.";
        return viewModel;
    }
}

使用 PRG 的想法,我重新编写了我的代码,如下所示:

[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]HomeIndexViewModel viewModel)
{
    return this.RedirectToAction("SaveSuccess");
}

public ActionResult SaveSuccess(HomeIndexViewModel viewModel)
{
    return this.View();
}

我遇到的问题是,在“历史记录”选项卡中,当我检查“SaveSuccess”请求时,我可以看到“模型绑定器”已启用,并显示正在使用的 DefaultModelBinder。但是,我使用自定义模型绑定器的索引请求没有启用该选项卡。

【问题讨论】:

    标签: tabs glimpse


    【解决方案1】:

    当给定页面请求存在模型绑定活动时,Glimpse 中的模型绑定选项卡将启用。如果没有模型绑定活动,该选项卡将显示为禁用。

    模型绑定选项卡的另一个常见问题是使用 PRG(POST REDIRECT GET)模式。

    如果包含模型绑定的操作方法重定向用户,则 Glimpse 将显示最后一个请求(即 GET),从而有效地隐藏模型绑定活动。您可以使用 Glimpse 中的 History 选项卡选择上一个请求(原始 POST)并查看模型绑定数据。

    最后,如果您使用ModelBinderAttribute(至少目前是这样),Glimpse 也无济于事。而是使用ModelBinders.Binders.Add() 或更好的IModelBinderProvider 来注册您的自定义模型绑定器。 Glimpse 会选择以这些方式注册的模型绑定器。

    【讨论】:

    • 我认为问题在于您提到的 PRG。我刚刚向操作方法发出了 AJAX POST 请求,并且启用了“模型绑定”选项卡(在我单击该请求的“历史记录”选项卡中的检查之后)。你能证明我可以用我的Index 操作方法解决问题吗?我做错了什么?
    • 你是对的。我按照此处给出的示例进行操作:judeokelly.com/… 现在启用了模型绑定选项卡。
    • 抱歉,我接受了答案。虽然我可以在使用 DefaultModelBinder 时分析“模型绑定”选项卡,但使用我的客户模型绑定器的请求不会启用该选项卡。我已经更新了我的代码以反映我现在正在尝试的内容。
    • 您的Index 操作方法没有任何问题,但如果您使用ModelBinderAttribute(至少目前是这样),Glimpse 将无济于事。而是使用ModelBinders.Binders.Add() 或更好的IModelBinderProviderModelBinderProviders.BinderProviders.Add()
    • 确定;我会看看我是否也可以为它整理一个简单的复制/测试用例。刚刚验证即使我明确地只是从 DefaultModelBinder 继承仍然不会触发选项卡。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多