MaviLe
MaviLe

Reputation: 15

How can I do it in C#?

How can I do it in c #

How to set output caching for an application in IIS? Programmatically

Upvotes: -2

Views: 67

Answers (1)

Ansil F
Ansil F

Reputation: 284

You can use OutputCache attribute over action method as below

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

If we want to have same type of OutputCache properties on multiple Action method or multiple controller, then we can use CacheProfile property. CacheProfile has several advantages. For example, we can change OutputCache property at multiple places from one central location and will apply without recompiling our Application. Add Caching section in system.web section, which will contain OutputCacheSettngs. In OutputCacheSettngs, we have added outputCacheProfiles with the name and other properties.

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

Go to your Action method or controller and add CacheProfile property in OutputCache Action

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

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

Upvotes: 2

Related Questions