【问题标题】:How can I do it in C#?我怎样才能在 C# 中做到这一点?
【发布时间】:2017-07-24 10:18:58
【问题描述】:

如何在 IIS 中为应用程序设置输出缓存?以编程方式

【问题讨论】:

    标签: c# iis config iis-6 web-administration


    【解决方案1】:

    您可以在操作方法上使用 OutputCache 属性,如下所示

    [OutputCache(Duration =20,VaryByParam ="ID")] 
    public ActionResult SearchRecord(int ID)   
    

    如果我们想在多个上拥有相同类型的 OutputCache 属性 Action方法或多个控制器,那么我们可以使用CacheProfile 财产。 CacheProfile 有几个优点。例如,我们可以 从一个中心更改多个位置的 OutputCache 属性 位置,并且无需重新编译我们的应用程序即可应用。添加 system.web 部分中的缓存部分,其中将包含 输出缓存设置。在 OutputCacheSettngs 中,我们添加了 outputCacheProfiles 的名称和其他属性。

    <caching>  
          <outputCacheSettings>  
            <outputCacheProfiles>  
              <add name="CacheFor100Seconds" duration="100" varyByParam="none" location="Server"/>  
            </outputCacheProfiles>  
          </outputCacheSettings>  
    </caching>  
    

    转到您的 Action 方法或控制器并添加 CacheProfile 属性 在 OutputCache 动作中

    [OutputCache(CacheProfile = "CacheFor100Seconds")]  
    public ActionResult MyAction()
    

    来自http://www.c-sharpcorner.com/article/outputcache-action-filter-in-asp-net-mvc/

    【讨论】:

      猜你喜欢
      • 2022-11-09
      • 2018-10-05
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      相关资源
      最近更新 更多