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

后端 未结 2 1728
心在旅途
心在旅途 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 20:02

    You didn't indicate whether or not the variables need to be persisted across page round trips or whether they are just used within each page's lifecycle.

    If they are not persisted across pages, then perhaps the easiest solution is to have all of your pages inherit from a based page class and then move the values from the module into the base page. This way you won't have to change any variable references, only page inheritance.

    If you do want to persist the values, completing the above changes makes it much easier to implement. You can then turn the member variables on the base page into properties and embed your user specific caching and fetching in the getter and setter.

    For example, instead of:

    Public MyVariable As String = ""
    

    You would have something like:

    Public Property MyVariable As String
        Get 
           Return GlobalMyVariableCache(UserNameKey)
        End Get
        Set (Value As String)
           GlobalMyVariableCache(UserNameKey) = Value
        End Set
    End Property
    

提交回复
热议问题