I've inherited an old ASP.Net Webforms application that makes heavy use of Session variables to store the database record IDs of user-submitted applications. This has caused some severe issues where users open up forms for different applications in multiple tabs, unwittingly overwriting information in one app with data meant for another.
Common usage throughout the application looks something like this:
// Get the application ID from the database
var appID = Convert.ToInt32(Session["appID"]);
// Update application using the above ID
UpdateDB("UPDATE Application SET Title='MY TITLE' WHERE id=" + appID);
// Redirect to another step of the form
Response.Redirect("/application/step-2");
Since this issue persists across numerous pages of the application, the solutions I've found are less than ideal (detailed at the end of this post).
My question: is there any way for me to prevent new tabs from overwriting existing session variables without having to rewrite Session access across the entire application?
Here are the solutions I've found that are more a less a last resort due to how much of the application would need to be changed:
Prepend
ViewState("_PageID")
to the session variableUse cookieless sessions (stored in the URL)
*The above solutions were found on the related post: asp.net - session - multiple browser tabs - different sessions?