Answer the question
In order to leave comments, you need to log in
Out of order page requests, browser or server bug?
I work with web forms asp.net. I'm making a captcha page. The captcha image is generated in the page_load of the page, written to the session and returned in response to a request from this page. In some cases (for example, spam in the f5 browser), the session and the user have different data. For the test, I made a page in which I indicated public int a; in page_load indicated
if (Session["a"] == null)
Session["a"] = a;
else {
Session["a"] = (int)Session["a"] + 1;
a = (int)Session["a"];
}
Answer the question
In order to leave comments, you need to log in
Maybe it's all true. You can hang up an Ajax request as a test (or a crutch) to finalize the session.
And in my opinion, there is a banal race condition. When we hold down F5, several requests can theoretically enter the processing pipeline at the same time.
Try putting the specified operations in a critical section:
lock (Session.SyncRoot) {
if (Session["a"] == null)
Session["a"] = a;
else {
Session["a"] = (int)Session["a"] + 1;
a = (int)Session["a"];
}
}
var storedValue = Session["a"];
a = (storedValue == null) ? a : (int)storedValue + 1;
Session["a"] = a;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question