I am porting a desktop program to asp.net. It uses shared variables (static in C#). So I was worried that if you have 2 users of the same website, if one changes the variable, it will be changed for the other user as
well. I tested this, and it seems to be true. If it isn't let me know. I created 2 asp.net pages, expt1.aspx and expt2.aspx, both of which have a link to expt3.aspx. Expt1.aspx sets a shared variable to '5'. You then click on a link in expt1.aspx
and then you are taken to expt3.aspx, which shows the value in a label. expt2 does the same thing, except it sets the variable to '7'.
So I opened 2 browsers (EDGE and chrome), opened expt1 in one, and expt2 in the second. I clicked on the link in expt1 in EDGE, and it produced a 5 in expt3. I clicked on the link in expt2 in Chrome and it produced a 7 in expt3. Then I did a refresh
of expt3 in EDGE - and it showed a 7!
This is hard to believe, so I just want to double check if shared variables are shared across users. It seems they are. The pages I used are listed below:
Public Class expt1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ClassConstantsEcho.expt = 5
End Sub
End Class
Public Class expt2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ClassConstantsEcho.expt = 7
End Sub
End Class
Public Class expt3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Label1.Text = "value of 'echo' is " & ClassConstantsEcho.expt
End If
End Sub
End Class
Member
61 Points
111 Posts
'shared' variables are shared across users of same website!
Mar 06, 2020 05:29 PM|RateFor|LINK
I am porting a desktop program to asp.net. It uses shared variables (static in C#). So I was worried that if you have 2 users of the same website, if one changes the variable, it will be changed for the other user as well. I tested this, and it seems to be true. If it isn't let me know. I created 2 asp.net pages, expt1.aspx and expt2.aspx, both of which have a link to expt3.aspx. Expt1.aspx sets a shared variable to '5'. You then click on a link in expt1.aspx and then you are taken to expt3.aspx, which shows the value in a label. expt2 does the same thing, except it sets the variable to '7'.
So I opened 2 browsers (EDGE and chrome), opened expt1 in one, and expt2 in the second. I clicked on the link in expt1 in EDGE, and it produced a 5 in expt3. I clicked on the link in expt2 in Chrome and it produced a 7 in expt3. Then I did a refresh of expt3 in EDGE - and it showed a 7!
This is hard to believe, so I just want to double check if shared variables are shared across users. It seems they are. The pages I used are listed below:
All-Star
160043 Points
13198 Posts
ASPInsiders
Moderator
Re: 'shared' variables are shared across users of same website!
Mar 06, 2020 05:45 PM|mbanavige|LINK
Shared/static variables are absolutely shared by all the web apps users.
If you want something user specific you could consider: