How to make the page expire....

  • Thread starter Thread starter Veeresh
  • Start date Start date
V

Veeresh

I am using .Net 1.1.
How to expire an .aspx page? I think I have to use HttpCachePolicy class for
this. But not sure how to use and where to this code to work. Is it in
Page_load event.
Thanks
Veer
 
Response.Expires = 0;

Gets or sets the number of minutes before a page cached on a browser
expires. If the user returns to the same page before it expires, the
cached version is displayed.

Bobby Ryzhy
bobby@ name of domain below
http://www.weekendtech.net
 
I have kept the code inside the Page_load event.
Here is my statement Response.Expires = 0
If I clcik on browser back button, still the page seems to be working and
not getting expired.
Veer
 
Perhaps the page is being cached somewhere.

To avoid that, try this code:

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

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
 
Stacy,
I have created a brand new web application with two web forms and tried with
the below code but no luck.
I really don't know why it is not workling. I presume any one can gerenate
this error.
Veer
 
Is it possible that a fresh version of your page is being requested, and
that there is no caching of any kind going on?
Exactly what is the behavior you expect that you are not seeing?

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
 
I have two web forms(WebForm1.aspx and WebForm2.aspx).
WebForm1.aspx is the stating page.
I have a button called Button1 and has clicked event statments as follows.
Response.Redirect("WebForm2.aspx").
I have in the following code in the Page_load event of WebForm1.aspx
Response.Expires = -1

Response.Cache.SetNoStore()

Response.AppendHeader("Pragma", "no-cache")

What I am expecting is:
1.User clicks on Button1 on WebForm1.aspx.
2. Take the user to WebForm2.aspx
3.If user clciks on browser back button, I want to tell the user that page
WebForm1.aspx is already expired.

I am using .Net 1.1 and IE. 6.0 and IE has the following settings.
Check for newer versions of stored pages: Every visit to the page
Ultimately I want to make sure that user cannot go back to login screen
after successfull login.
Thanks for your all replies.
Veer
 
Put some code into your login screen for this.
I assume you're setting a UserID or something like that on your login page
after a successful login.
So in your login screen's Page_Load event you can do something like this:

'If the user is already logged in, take them elsewhere
If Not Session("UserID") Is Nothing Then
Response.Redirect("ErrorPage.aspx")
End If

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
 
Steve,
I am thankfull to you for answering my questions.
Page_Load event is not getting called when the user clicks on browser back
button. So the logic below is not working for me. IS there anyway when the
user runs my application I can totally take out this browser navaigational
buttons. This back button is creating problem in other part of the
application too.
Veer.
 
Steve,
The following code worked for me.

Response.Cache.SetExpires(DateTime.Now.AddSeconds(0)) '1

Response.Cache.SetCacheability(HttpCacheability.NoCache) '2

Response.Cache.SetValidUntilExpires(False) '3

Response.Cache.VaryByParams("Category") = True '4

Really don't know how it is working. Really don't know the significance of
line 4. If I comment the line 4, the entire logic does not work.

Veer
 
It seems to me you were manually caching your page.
I don't know why you were doing that when it seems like your goal was to not
cache the page.
 
Now I have used only one statement as follows.
Response.Cache.SetCacheability(HttpCacheability.NoCache)
The above code is forcing the Page_Load event to trigger even when the user
clicks on browser back button. Once I am sure of triggering this event all
the time I can always check whether user already logged in or not using the
following code.

If Not Session("MyVariableName") Is Nothing Then

'User already logged in to the system

Response.Redirect("myNextPage.aspx")

End If

Thanks for your all answers.

Hopefully all these theory is good for production environment!!!
Veer
 
Back
Top