Force Page Expire

J

J

Here is the code that I tried with no luck. Even though the cache is
not saved, the page still appears but goes to the server to get the
page instead of local cache. When it comes back to the page load event
the ViewState no longer exist but the session does.

Any help would be greatly appreciated!


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then

If IsExpired() Then
Response.Redirect("expired.aspx")
Else
Me.SaveTimeStamps()
End If
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetExpires(Now().AddSeconds(-1))
Response.Cache.SetNoStore()
Response.AddHeader("Pragma", "no-cache")
End If
End Sub

Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs)

End Sub
Private Sub SaveTimeStamps()
Dim t As DateTime = Now
ViewState.Add("TimeStamp", t)
Session.Add("TimeStamp", t)
End Sub
Private Function IsExpired() As Boolean
If Session("TimeStamp") Is Nothing Then
Return False
ElseIf ViewState("TimeStamp") Is Nothing Then
Return False
ElseIf ViewState("TimeStamp").ToString =
Session("TimeStamp").ToString Then
Return False
Else
Return True
End If
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'Just posts back to itself
End Sub
End Class
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top