NoCache not working. Tried everything

J

Jeff C

Hello everyone.
If I hit the back button on my data entry form I can still get the
cached page. I have tried
<%
pStr = "private, no-cache, must-revalidate"
Response.ExpiresAbsolute = #2000-01-01#
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", pStr
%>
and
Response.Buffer = True
Response.ExpiresAbsolute = Now().Subtract(New TimeSpan(1, 0, 0,
0))
Response.Expires = 0
Response.CacheControl = "no-cache"
Response.Cache.SetCacheability(HttpCacheability.NoCache)

but nothing seems to work. I really need help on this. It's a data
entry form and I can't have them have the ability to use the back
button and get data.
Here is my page load in codebehind
____
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Cache.SetCacheability(HttpCacheability.NoCache)

cmdClearSearch.Attributes.Add("onclick", "return confirm('This
will clear all search criteria, continue?')")
PopulateForm()
End Sub
____

Here is my .aspx page stuff
<%@ Page language="VB" AutoEventWireup="false"
Codebehind="FirstSave.aspx.vb" Inherits="myapp.myapp"%>
<%@ Register TagPrefix="myapp" TagName="bar" Src="bar.ascx" %>

<% System.Web.HttpContext.Current.Response.AddHeader("Cache-Control","no-cache")
System.Web.HttpContext.Current.Response.Expires = 0
System.Web.HttpContext.Current.Response.Cache.SetNoStore()
System.Web.HttpContext.Current.Response.AddHeader("Pragma",
"no-cache")%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML> (etc...)


Please help!
Thanks much!
 
B

bruce barker

let the asp.net do the work:

Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);


-- bruce (sqlwork.com)
 
S

Steve C. Orr [MVP, MCSD]

To prevent caching I use this code:

Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")

But maybe that's not really your problem. Perhaps when they hit the back
button your page is being requested again, not pulled from the cache. Try
putting a breakpoint in your page load event so you can be sure.
 
J

Jeff C

Thanks for the help so far, but let me explain one more thing.

Users are sent to the database data entry form in which then enter
some amount of data, hit submit which processes the data with SQL SP's
and then reloads the page with an empty form. As it stands now, when
they submit the form could come back empty as I could put some code to
clear the text boxes etc... but if they press "back" the would be
brought back to the pre- postback page with all the data filled in.
This is what I want to prevent. I want them to see a "Warning, page
has expired" page. What am I doing wrong?
Thanks all!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top