how to enable cache for static content in asp.net web development?
Ask by ICSM Computer
Updated 05 Aug 2025
To manage HTTP cache control directives like
public,private,no-cache, etc. in ASP.NET Web Forms or MVC (not Core), you typically set them in:web.config– for static content1. Set Cache Directives in
web.config(Static Content)Examples:
public– allow CDN/proxies to cache.private– only browser can cache.no-store– prevent all caching.no-cache– requires validation before use.2. Set Cache Control in ASP.NET MVC Controllers (Dynamic Content)
Use the
Response.Cacheobject.publicCache Example:privateCache Example:no-cacheExample:3. Web Forms Page Level Caching (
@OutputCache)Set caching and scope directly on
.aspxpage:Location Options:
Any→ Same aspublicClient→ Same asprivateNone→ No cachingServer→ Cache only on serverSummary of
HttpCacheabilityin ASP.NETPublicpublic, max-age=...Privateprivate, max-age=...NoCacheno-cacheNoStoreno-storeServerServerAndNoCacheno-cache(for server-side cache)View Result in Browser
Use Chrome DevTools → Network tab → click any static/dynamic response → check Headers for: