ASP.NET - Google Chrome caching DropDownList selec

2019-07-17 02:53发布

问题:

I'm experiencing what seems to be a caching issue with Google Chrome and Safari on my cart page. In the cart there are 2 dropdown lists. When you hit the checkout button after changing the values in the dropdown lists, it commits what's selected in the lists to the database.

It's a little bit hard to explain the unexpected behavior so I will try to write it out step by step with an illustration of my problem.

Lets say the first dropdown list has the values of:

  • VALUE1
  • VALUE2
  • VALUE3

And the second dropdown list has the values of:

  • DUMBO1
  • DUMBO2
  • DUMBO3

I add an item to my cart.

Screen Says: VALUE1, DUMBO1

Database Says: VALUE1, DUMBO1

I hit Checkout.

Database says: VALUE1, DUMBO1 (I can't see the dropdown lists after I hit checkout because i'm not at the cart page)

I hit the back button.

Screen Says: VALUE1, DUMBO1

Database Says: VALUE1, DUMBO1

I drop down the VALUE1 combo and select VALUE2, VALUE2 is selected momentarily and then the site posts back and VALUE1 is re-selected in the drop down list (from being reloaded from the DB)

MOMENTARILY Screen Says: VALUE2, DUMBO1

Database Says: VALUE1, DUMBO1

THEN AFTER POSTBACK FROM DROPDOWNLIST_SELECTIONCHANGED EVENT

Screen Says: VALUE1, DUMBO1

Database Says: VALUE1, DUMBO1

Hit Checkout.

Database Says VALUE1 ,DUMBO1 (I can't see the dropdown lists after I hit checkout because i'm not at the cart page)

Go back.

Screen Says: VALUE2, DUMBO1

Database Says: VALUE1, DUMBO1

So it appears that it's remembering my selection of VALUE2 even though it jumped back to VALUE1 before I checked out.

It seems to be a caching problem, however I've got some no-cache code to prevent caching of that page that works great in firefox and internet explorer but seems to be failing in Chrome and Safari. I'm basically returning in the headers for the cart page: no-cache, no-store, and must-revalidate to attempt to prevent caching, but based on this scenario it seems to be caching the page anyway and not reloading it when I hit the back button.

I am open to any solutions or suggestions at this point. Thanks!

回答1:

I had a similar problem and I have spent several days testing only to find no answer.

Suppose we have a dropdownlist filled with colors. each time I change the value I make a partial postback with ajax to save the value and do a couple more things like checking stocks.

I choose (in this order): red, white, blue, green.

then I hit checkout and when I go back to my surprise the red color is selected. I go back again and I get white selected. then blue and finally green after going back four times.

I tried at IE and FF and found there it works fine so it's not a bug in the code. it has to be something with the chrome.

anybody can help with this?

edit: I tried with another webpage I'm making and there it works fine but I can't find any differences between them that could cause it.

Edit2: I found a way to "solve" it using ScriptManager.RegisterStartupScript at the navigate event to write a script that sets the values correctly instead of doing it at codebehind. It's not a very elegant way but it worked for me and I hope for others with a similar problem.