By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,786 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,786 IT Pros & Developers. It's quick & easy.

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

P: n/a
Rob
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.
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Nov 18 '05 #2

P: n/a
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...webuipageclass
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.)

Nov 18 '05 #3

P: n/a
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/a...ods/open_0.asp
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.