1

次のコードを想定してみましょう。

[OutputCache(Duration=60,VaryByCustom="Browser")]
public ActionResult CachableAction(string SomeParameter)
{
   return View();
}

そんなこと知ってるOutput caching lets you store the output of an action method in memory on the Web server. For example, if the action method renders a view, the view page will be cached.

デバッグ構成でページをキャッシュしたくありません。

Release構成ではなく キャッシュのみを適用するには、どのような設定が必要Debugですか?

私はVS2010を使用しています。

4

3 に答える 3

3

属性については、プリプロセッサ ディレクティブを使用することができます

#if !DEBUG
[OutputCache(Duration=60,VaryByCustom="Browser")]
#endif
public ActionResult CachableAction(string SomeParameter)
{
   return View();
}
于 2012-09-26T06:34:21.453 に答える
2

web.config.debug ファイルは、展開パッケージをビルドする場合にのみ使用されます。たとえば、サイトを Cassini でローカルに実行すると、完全に無視されます。したがって、web.config でキャッシュを無効にしてみてください。

<caching>
    <outputCache enableOutputCache="false" />
</caching>

web.config.release でキャッシュを有効にします。ただし、Web 配置パッケージ機能を使用しない場合、これらのファイルは完全に無視されることに注意してください。

于 2012-09-26T06:35:08.490 に答える
0

これは、コントローラーのテストプロジェクトで行っています。以下のようにします

[OutputCache(Duration = 10, VaryByParam = "ParamA;ParamB;")]
        public PartialViewResult CachData(string someparameter)
        {
            string returnvalue = string.Format("parameter :{0} date : {1}", someparameter, DateTime.Now.ToString());
            return PartialView("CachData", returnvalue);
        }

そして私の見解では

@model string 
<p>
    This is my cach Action</p>
@Html.Raw(Model)

私はこれがあなたを助けると思う...

于 2012-09-26T06:29:39.100 に答える