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

Discussion in 'ASP .Net' started by =?Utf-8?B?Um9i?=, Jan 15, 2004.

  1. 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.
     
    =?Utf-8?B?Um9i?=, Jan 15, 2004
    #1
    1. Advertising

  2. 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
     
    =?Utf-8?B?TWljaGFlbCBJYW50b3NjYQ==?=, Jan 15, 2004
    #2
    1. Advertising

  3. 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.)
     
    Steven Cheng[MSFT], Jan 16, 2004
    #3
  4. 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
     
    Steven Cheng[MSFT], Jan 21, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Itai
    Replies:
    0
    Views:
    552
  2. Simon
    Replies:
    3
    Views:
    4,289
    Joerg Jooss
    Jan 15, 2005
  3. =?Utf-8?B?VGltIFN0YWxs?=

    RE: Suppress postback added to history WITHOUT smartnavigation

    =?Utf-8?B?VGltIFN0YWxs?=, Mar 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    695
    =?Utf-8?B?VGltIFN0YWxs?=
    Mar 8, 2005
  4. Pål A.
    Replies:
    2
    Views:
    633
    Pål A.
    Feb 25, 2008
  5. Itai
    Replies:
    0
    Views:
    174
Loading...

Share This Page