开发者

Issue with asp.net web pages being cached

开发者 https://www.devze.com 2022-12-25 22:32 出处:网络
I want to prevent my asp.net / c# 2008 web pages from being 开发者_开发百科cached on the client side or the server side.

I want to prevent my asp.net / c# 2008 web pages from being 开发者_开发百科cached on the client side or the server side.

How can I go about doing that?


For the client side you want to use the No-Cache

http://www.i18nguy.com/markup/metatags.html

Here is a link describing how to configure the response object for no caching on the server side:

http://www.extremeexperts.com/Net/FAQ/DisablingBackButton.aspx

Response.Buffer = True  
Response.ExpiresAbsolute = Now().Subtract(New TimeSpan(1, 0, 0, 0)) 
Response.Expires = 0 
Response.CacheControl = "no-cache"


The page is being cached, so the solution to not make it cached on the client side is to put this tag:

<%@ Outputcache Location="None"%>

before the page tag:

<%@ page >

The result looks like this:

<%@ OutputCache Location="None" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>


In your question, you specify no cache on both the client and server. To me this means no caching anywhere.

This will prevent any caching from happening anywhere.

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

Either put this in the load of the page(s) you don't want cached or create a base page class.

from http://skysanders.net/subtext/archive/2010/03/23/preventing-caching-of-content-in-asp.net-pages-and-other-httphandlers.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号