So I’ve recently gotten to the stage a project I’ve been working on has been deployed internally in our small business.


If you imagine the app pulls a list of all names from a DB. It then checks a “hide” list, and removed any items on this list, before returning a view with the list of names (minus the ones to be hidden).
The first time this runs it shows all names, and the user through the UI has a Hide button, so can then start adding names for hiding, when the page is refreshed (either with a view change or on a manual timer every few mins), the list is shown as expected on my dev laptop.
However now it’s deployed I’m getting strange feedback that sometimes it’s not working as it should, and that sometimes any changes are discarded, and infact I’ve loaded the hosted page myself and instead of it starting with a full list, it displays a list with names already hidden by another user?!
I was under the impression that each client browser that visits the website would have their own completely “fresh” instance of the web app served, so anything that is added to the Hidden list by other users in their sessions would be irrelevant?
I tried to test this locally on my machine, with two browsers and it shows the same behaviour, I put this down to it thinking it’s the same PC, so that’s that? Maybe not!!
To make deployed troubleshooting worse the site sits on a few servers load balanced by a Netscaler, so sometimes I see expected behaviour, (I’m guessing the users are looking at different IIS servers), and sometimes I see it happening where their variable lists for hidden names are affecting other instances?
So my understanding here is wrong somewhere! I’d have though all visitors get a different experience entirely and are not linked?
The command as I say for removing the names involved a button that sends a GET to the web server, which then adds the name provided by the request to a List, then the Return View of course calls the database and removed any matching items from the list in its processing.
Any ideas what’s going on? For example me switching Reddit to Dark Mode should affect everyone else!!
Maybe I could work around by removing the table row to be hidden in JS somehow, rather than in my C# server side code, but I’d rather understand what’s happening and make it work properly!
Thanks for your help!
How/where is the list of hidden items stored?
In the Index controller.
Used in the context:
Foreach (var hiddenName in AppModel.HideList)
And the AppModel containing;
Static AppModel() { HideList = new List<string>(); }
The IActionResult for the Get for hiding the name is:
Public IActionResult Hide (string id) { AppModel.HideName(id); Return RedirectToAction(“Index”); }
And the Hide and method is….
Public static void HideName(string id) { HideList.Add(id); }
Apologies for any typing errors that’s typed on my phone screen rather than copy & pasted.
Should give you a rough feel for how it’s working (or not).
My understanding was each client connects to the URL and the server serves them a completely independent site, so any variables would be independent to each client. Perhaps not?
Maybe customisation like this filtering should be done clientside with JS? (But then my page refresh timer would cause it all to reset).
But ideally I’d like each user to be able to customise their list as they see fit, independently of one another, using server side C#.
A couple guesses…


How are you linking the user to the preferences table? If it’s AD lookup, make sure you’re requiring authentication. If not, users could be found as anon and a shared record could be in use.
If you’re using Entity Framework, try AsNoTracking and converting IQueryable to concrete List right after lookup to prevent any server-side EF voodoo.
There is no authentication used at all.
The HideList is a List<string> in one of the models.
The Index controller declares the variable.
There is no data pushed to the DB for this, it’s done with variables in the controller.
I don’t use EF at all actually, Dapper is used for querying the database, but I don’t think that’s important for the behaviour here which is all in a variable.
Your post doesn’t contain a lot of useful details and there’s a million ways to set up ASP.NET apps, but generally, no, the hosting environment will not start a new instance (as in process or app domain) of your application for every request. If you’re storing data in instance fields of a controller, it’ll be gone by the next request. If you’re storing data in static fields it’ll be shared among anyone who happens to connect to the same instance of your application.
What you’re looking for is session state.
Thanks, I’ll look in to session state.
I put some small bits of the code in another comment reply, but the HideList is declared in a model class with public static List<string> HideList;
So your comment that static fields will be shared by users kind of explains what I’m seeing, however it’s complicated as I guess that’s only between users on the same server, if the load balancer sends them to another server the behaviour is not experienced!
In the absence of authentication another user suggested cookies may be a good way to store this list of user preferences for hidden names.
C# devs
null reference exceptions

source