State management

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a web form which displays some information based on criteria I store
in the session. When the user interacts with the page it is changed and
session changed accordingly. The use can navigate from the page ok, if they
click back all is ok because the session still relates to the page. However
there may be a situation when the user navigates to a new version of the page
(type in the url etc). How I have a page in the browser history to which the
user can use the back button to navigate to, to which the current values in
the session have no relation.

Here's what I want to do, if the user presses back, detect the page does not
match the session and update the page with the current session values. But
the page load event is not fired, so how do I trigger my update code.
 
you would need to track the page and some other request specific information
and add it to session to be able to determine where the user is from history

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
_________________________
 
Hi,
Thanks for the reply, but I don't understand how to do this. Can you
elaborate.
Tim

Alvin Bruney said:
you would need to track the page and some other request specific information
and add it to session to be able to determine where the user is from history

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
_________________________


Tim Marsden said:
Hi,

I have a web form which displays some information based on criteria I
store
in the session. When the user interacts with the page it is changed and
session changed accordingly. The use can navigate from the page ok, if
they
click back all is ok because the session still relates to the page.
However
there may be a situation when the user navigates to a new version of the
page
(type in the url etc). How I have a page in the browser history to which
the
user can use the back button to navigate to, to which the current values
in
the session have no relation.

Here's what I want to do, if the user presses back, detect the page does
not
match the session and update the page with the current session values. But
the page load event is not fired, so how do I trigger my update code.
 
It sounds as if you need to store more than one entry in your session state.
One for the previous state of things, and then one for the current state
of things. You'll need to then detect in your page which one to use.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Hi Tim,

I think the problems here is that when the user hit the "back" button on
browser, the displayed page is by default retrieved from the client's
cache(if we didn't explictitly disable the page's client cache). I think
that's why you'll find the Page_load not fired. IF the page is actually
retrieved from severside , the Page_load will surely be fired.
In addition, as for detecting whether the page is requested the first time
or specifying a version info, I think we can add a certain version field(a
timestamp) in the page's viewstate at the first request( !IsPostBack), and
if there is no such field , it means it's the first request or if the info
is different from the session's data, we need to update the page. But this
depends on the page is not retrieved from client cache when user hit "back"
button. How do you thnk of this?

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Thanks Steven,

I can place a time stamp on the page, and then one in the session, if they
match the session is for the page, ok I understand that. But what I am
struggling with is how to test the page timestamp against the session if
there is no event fired when the page is displayed via the back button. If I
could detect the page being loaded I could refresh it with the current
session info. I can set up a JavaScript function which is fired onload, but
can I link this into my vb code behind.

An example might be a banking app. I logon on and view my balance. After
navigation away from the page I return via the back button. It does not show
me the balance page but displays the logon page for my account.

Regards
Tim
 
Thanks for your followup Tim,

As for the
==================
. I logon on and view my balance. After
navigation away from the page I return via the back button. It does not
show
me the balance page but displays the logon page for my account.
==================

what's the logon page? Are you using the Forms based authentication to
protect your page? If so, is this behavior caused by the user's
authentication session timeout?

Also, since your balance page need to be accurate and sychronous, I suggest
that you disable the clientside cache for that page. Thus, when the user
trying to hit "back " button at client browser to navigate back to the
balance page, it will get a "content expired error message" or just request
the page again from the serverside. Then, as long as the page is requested
from serverside, we can detect the entering of the Page_Load event.(If
still have no luck with the Page_Load, there must have some other things
incorrect with the page). To disable clientside cache for a page, we can
add the following statements in Page_Load:

private void Page_Load(object sender, System.EventArgs e)
{
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;
}


Also, here are some public articles describing this:

http://blog.u2u.info/DottextWeb/gert/archive/2005/01/17/808.aspx

http://www.c-sharpcorner.com/asp/Articles/CachingInASPDPL.asp

HTH. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top