"Previous page" ?

T

TR

In an "Abandon Changes" button on my UserPreferences.aspx form, I'd like to
redirect back to the page the user was on before coming to the
UserPreferences form. It could be any one of my web app's pages with a link
to the UserPreferences page in its topmenu. (I'm testing for stale session
tokens and can prevent users from bookmarking the page.) However, in
codebehind for the AbandonChanges click event, the REFERRER is the
UserPreferences page itself, having posted to itself. Does asp.net keep
track of the "actual previous page" so to speak, when the previous page is
from the same web application? Or is that sort of state tracking up to the
developer?
Thanks
 
K

Kevin Spencer

Hi TR,

The problem you're dealing with is a facet of the WebForm object model. As a
WebForm posts back to itself, and the Referer is the last page visited, the
Referer is as likely to be the same page as it is to be another.

The solution is to keep track of the Referer (persist it in ViewState, most
likely) after the first time the page is visited. This can be done using a
conditional statement to check if the Referer's URL is the same as the
current page, and only saving it if it is not.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 
T

TR

Thanks for the helpful suggestion, Kevin.
TR

Kevin Spencer said:
Hi TR,

The problem you're dealing with is a facet of the WebForm object model. As a
WebForm posts back to itself, and the Referer is the last page visited, the
Referer is as likely to be the same page as it is to be another.

The solution is to keep track of the Referer (persist it in ViewState, most
likely) after the first time the page is visited. This can be done using a
conditional statement to check if the Referer's URL is the same as the
current page, and only saving it if it is not.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top