How to get a public variable (in a Module) to NOT share value between users

后端 未结 2 1730
心在旅途
心在旅途 2021-01-21 19:23

I\'m working in an ASP.NET (VB) Web Application with Windows/Active Directory Authentication

I am using a module so that I can call public subroutines and functions, and

2条回答
  •  情歌与酒
    2021-01-21 19:57

    The problem you are coming across is a very common one in web programming. A Module's members are static - meaning there is one instance of them across the entire AppDomain of your application. Every user that accesses these will get the same object - you have already learned this.

    Your options are exactly what you described. You could possibly replace the public variable in your module with a property whose getter you write to access a user-specific field in a dictionary (please remember thread safety when writing this getter code).

    The much easier solution would be to use the Session. Session values are stored server-side and are user specific. The only thing that get's sent client side is the session key, and if you are using .Net authentication, this is likely already getting sent.

    Good luck,

提交回复
热议问题