Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to prevent Postback URL's from being added to browser history

Reply
Thread Tools

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

 
 
=?Utf-8?B?Um9i?=
Guest
Posts: n/a
 
      01-15-2004
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.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljaGFlbCBJYW50b3NjYQ==?=
Guest
Posts: n/a
 
      01-15-2004
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
 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-16-2004
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.)

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-21-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solution for posterity: GridView, Datakeys, and "Item has already been added. Key in dictionary: 'CategoryID' Key being added: 'CategoryID'" ASP .Net 2 11-02-2006 04:48 AM
RE: Suppress postback added to history WITHOUT smartnavigation =?Utf-8?B?VGltIFN0YWxs?= ASP .Net 0 03-08-2005 12:19 AM
Prevent postback saved into history of Internet Explorer Simon ASP .Net 3 01-15-2005 10:24 AM
How does smartNavigation prevent Postback URL's from being added to the browser History? Itai ASP .Net Web Controls 0 08-10-2004 04:31 AM
How does smartNavigation prevent Postback URL's from being added to the browser History? Itai ASP .Net 0 08-10-2004 04:29 AM



Advertisments