为什么禁用Glimpse模型绑定选项卡?

时间:2013-04-17 18:10:37

标签: tabs glimpse

我正在使用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();
}

我遇到的问题是,在History选项卡中,当我检查“SaveSuccess”请求时,我可以看到“Model Binder”已启用,adn显示正在使用的DefaultModelBinder。但是,我使用自定义模型绑定器的索引请求不启用选项卡。

1 个答案:

答案 0 :(得分:3)

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

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

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

最后,如果您使用ModelBinderAttribute(至少目前),Glimpse无法提供帮助。而是使用ModelBinders.Binders.Add()或更好的IModelBinderProvider来注册您的自定义模型绑定器。 Glimpse选择以这些方式注册的模型粘合剂。