How to prevent Postback URL's from being added to browser history

G

Guest

Each time a webform is posted back (submitted), another URL is added to the browser's history list. My web application allows a back button to return to previously visited pages, but I do not wish to return to each Postback URL, but rather only the initial page URL. Is there a way to prevent Postback URL's from being added to the browser's history list

Thanks in advance for any help.
 
G

Guest

If you turn on smart navigation (Page.SmartNavigation property) on the page it will prevent postbacks from being added to the history (as well as other nice features). CHeck out browser compatibility issues though to make sure it works in non-IE browsers - or at least see if it fails gracefull

hope this help
Michael
 
S

Steven Cheng[MSFT]

Hi,


Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you are looking for some approachs on how to prevent
Postback URL's from being added to the browser's history list so that
customer can only navigator to the initial view of a page or refresh again
to get a new version of the certain page.
If there is anything I misunderstood, please feel free to let me know.

First of all, I should confirm msdnalias's suggestion that use the
"SmartNavigation" property of the ASP.NET web page. This is a very good
solution. In fact, one of the functionality fo "SmartNavigation" property
is:
retaining only the last page state in the browser's history.
Thus, only the different navigatored page will be added to the history
list. The post back page with same url won't be added into. To enable the
"SmartNavigation" property, just change the certain page's
"smartNavigation" property to "true" in the property window of VS.NET, also
you can programmatically set it as below:
Page.SmartNavigation = true;

Also, there're many other wonderful features of the "smartNavigation"
property, for detailed info, you can view the following link in MSDN:
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuipageclass
smartnavigationtopic.asp?frame=true


In addition, as for the history page which we can visit use the "back" or
"forward" button of IE, they're all the page cache on the client machine.
If you don't want the client cache for a certain, you may also manually
disable them on the serverside code, such as:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;

}

Thus, if you request this page and then navigator to other pages or event
fire some post back events of the page and then use "back" button to go
back. The Browser will display the following information:
----------------------------------------------
Warning: Page has Expired The page you requested was created using
information you submitted in a form. This page is no longer available. As a
security precaution, Internet Explorer does not automatically resubmit your
information for you.

To resubmit your information and view this Web page, click the Refresh
button.
----------------------------------------------

Thus, will also force you to refresh the page and request a new version of
it. And here is a KB article which particularly discus on this tech topics,
you may have a look if you have interests:

#HOWTO: Prevent Caching in Internet Explorer
http://support.microsoft.com/?id=234067

Any way, please check out the preceding suggestions and choose the proper
one as you like. Also, if you feel them still not quite suitable for your
situation, please feel free to let me know. I'll be willing to help you
search for some other approachs.



Regards,

Steven Cheng
Microsoft Online Support

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

Steven Cheng[MSFT]

Hi,


I've reviewed the issue and found that one suggestion I provided in the
last reply need a bit modification. When only using the below code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;

}

the end user will see an error "Warning: Page has Expired ...." if the page
is expired and the end user tries to use the "back" button. Actually, it's
a little more complex. You only get the page expired warning if you
previously submitted the page prior to clicking the back button.

To avoid this, we can use the new code as below:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;

if(IsPostBack)
{
Response.Write("post back");
}

}
Then we browsed the page followed by browsing some other page. Then we
clicked the back button and we can see this page with the button on it.
There was no "page has expired" warning message.


---
Also, there is another way to keep a page from being in the history list is
to use window.open("NewPage.aspx",,,false). This must be done when LEAVING
the page that you don't want in the history. The new page replaces the
previous page in the history list. See
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/open_0.asp
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top