2

Glimpse MVC4 バージョン 1.2.0 を使用しています。

ブラウザで Glimpse UI を開くと、[Model Binding] タブが無効になっていることに気付きました。有効にする方法がわかりません。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」リクエストを調べると「Model Binder」が有効になっていることがわかり、DefaultModelBinder が使用されていることを示していることです。ただし、カスタム モデル バインダーを使用するインデックス リクエストでは、タブが有効になりません。

4

1 に答える 1

3

Glimpse の [モデル バインディング] タブは、特定のページ リクエストに対してモデル バインディング アクティビティがある場合に有効になります。モデル バインディング アクティビティがない場合、タブは無効に表示されます。

モデル バインディング タブに関するもう 1 つの一般的な問題は、PRG (POST REDIRECT GET) パターンの使用です。

モデル バインディングを含むアクション メソッドがユーザーをリダイレクトする場合、Glimpse は最後のリクエスト (GET) を表示し、モデル バインディング アクティビティを効果的に隠します。Glimpse の [履歴] タブを使用して、前の要求 (元の POST) を選択し、モデル バインディング データを表示できます。

ModelBinderAttribute最後に、Glimpse を使用しても (少なくとも現在は)役に立ちません。代わりにModelBinders.Binders.Add()またはを使用IModelBinderProviderして、カスタム モデル バインダーを登録します。Glimpse は、このように登録されたモデル バインダーをピックアップします。

于 2013-04-17T18:53:43.473 に答える