I have a asp.net website and a class library as a project reference. In the class library I have public class a couple of static methods. When user logs into their account, I make a call to one of the static method to load the info related to the user. I had some instance where when I login as user A, I am able to see info related to user B. Is this because of static methods?
Share
No, it’s because of static variables. Those are shared by the whole
AppDomain– which pretty much means “the whole website on that machine” in this case.It’s hard to know exactly what you should be doing without any more information, but I strongly suspect you’re just storing user information in static variables, which is never going to be the right way to go.
Quite how you manage user sessions is up to you, and reams of text have been written on this no doubt – but using static variables will cause exactly the issue you’ve seen.