R
RB
Hi clever people
I've noticed a lot of people stating not to use static variables with
ASP.NET, and, as I understand it, the reason is because the variable is
shared across user sessions - which is Very Bad (tm) for reasons I
understand!
However, does this rule apply only to global static variables, or does
it apply to procedure-level static variables.
e.g. If I have a class:
==================================================
Public Class MyPretendClass
Inherits System.Web.UI.Page
ReadOnly Property SomeProperty() As Integer
Get
Static i As Integer = -1
If i = -1 Then
i = Integer.Parse(Request.Params("MyQueryStringArgument"))
End If
Return t
End Get
End Property
' REST OF CLASS, INCLUDING USE OF SomeProperty PROPERTY
End Class
==================================================
and I output SomeProperty to an asp:Label how will it work if I have 2
users (Alice and Bob), where Alice requests the page with a query string
value of 1, and Bob then accesses the page with a value of 2.
Obviously Alice will have 1 in the label, but what value will Bob have?
Many thanks,
RB.
I've noticed a lot of people stating not to use static variables with
ASP.NET, and, as I understand it, the reason is because the variable is
shared across user sessions - which is Very Bad (tm) for reasons I
understand!
However, does this rule apply only to global static variables, or does
it apply to procedure-level static variables.
e.g. If I have a class:
==================================================
Public Class MyPretendClass
Inherits System.Web.UI.Page
ReadOnly Property SomeProperty() As Integer
Get
Static i As Integer = -1
If i = -1 Then
i = Integer.Parse(Request.Params("MyQueryStringArgument"))
End If
Return t
End Get
End Property
' REST OF CLASS, INCLUDING USE OF SomeProperty PROPERTY
End Class
==================================================
and I output SomeProperty to an asp:Label how will it work if I have 2
users (Alice and Bob), where Alice requests the page with a query string
value of 1, and Bob then accesses the page with a value of 2.
Obviously Alice will have 1 in the label, but what value will Bob have?
Many thanks,
RB.