ASP.NET Browser Indicates “Webpage Expired” For Back Button (After Message)

I am having problems with a simple ASP.NET application and the back button after posting back.

This page has a simple form, some text fields, etc., as well as a drop-down menu that does postback (auto-repeat).

A “normal” stream is a user filling out a form and possibly changing a drop-down list. Based on the dropdown value, the contents of the page may change.

The problem that I encountered is that after the user has changed the drop-down list and the aftereffect is completed, the user clicks the "Back" button. They see the message "webpage has expired" from IE.

I installed the following:

Response.Cache.SetExpires(DateTime.Now.AddMinutes(-1)); Response.Cache.SetCacheability(HttpCacheability.Private); 

But this does not seem to be a problem.

The actual header of the Cache-Control response reads: private, no-cache: "Set-Cookie"

In a classic ASP application with a Cache-Control response header, only the "private" back button behaves as expected after the "post back".

Is there a way to get ASP.NET to fine tune cache control exactly to "private"? Or any other solution that makes the back button and feedback work well together?

Thanks!

+6
source share
2 answers

Depending on the situation, you can avoid this hack / workaround:

  private void Page_PreRender(object sender, System.EventArgs e) { if (IsPostBack && !IsCallback) { Response.Write("<html><head><script>location.replace('" + Request.Path + "');\n" + "</script></head><body></body></html>\n"); Response.End(); } } 
+2
source

What you are dealing with is actually an old problem. Essentially, the reason you see the “webpage has expired” message is because one of the methods to disable the back button was used. This method sets the cache to a date in the past, so the browser should show this error if the user clicks the back button.

This will be a line of code:

 Response.Cache.SetExpires(DateTime.Now.AddMinutes(-1)); 

This was a problem, especially with ASP.NET WebForms due to the way postback works compared to other frames.

For a detailed explanation of all the issues raised, I highly recommend reading the article below. He does not answer your question directly, but I think that you will get more information from him than a simple answer that will help you analyze your options, armed with a better understanding of the problem. Be sure to read parts 1 and 2.

http://www.4guysfromrolla.com/webtech/111500-1.shtml

I have an idea on how to make the back button behave like a back button, so postbacks are not considered page navigation:

Personally, I took a (possibly hacky / messy) approach to just put things in the UpdatePanel when I don't need the postbacl / back button conflict, since I use Ajax in most of my applications. This forces the back button to return to the previous page, instead of standing on the same page, but returning to the control values, as it was before the postback.

+1
source

Source: https://habr.com/ru/post/911121/


All Articles