DANGER - WARNING - Big Problem using with ASP.NET!
Posted: 4/6/2005 2:35:40 PM
By: Comfortably Anonymous
Times Read: 2,031
0 Dislikes: 0
Topic: Programming: .NET Framework
Parent Message
Just discovered a big huge problem when doing the "Public Shared trick" with ASP.NET!  Do NOT use Public Shared with ASP.NET unless you need Application Global (Not Session Global) scope:

I had assumed that Public Shared would be localized (scoped) to a single ASP.NET session. I was very much wrong! Anything declared as Public Shared is accessible from ALL SESSIONS. Expect extremely unexpected behavior with your ASP.NET web app if declaring your variables as Public Shared and expecting them to be accessible across your entire application, but local to a single user.

Although I hate using untyped variables in ASP.NET, make sure that you use Session("VariableName") for your variables which should be accessible only to a single user (session) across the entire application.

Although, I have come up with somewhat of a compromise to use Typed Session Variables with ASP.NET. It's not perfect, but it's better than nothing, and still allows and enforces the use of typed variables, but all the nice Intellisense auto-complete does not work with it, so your design errors turn into runtime errors rather than designtime errors. :(

I am at work right now, so will write up how to do this tonight with the separate title "HOWTO: Typed Session Variables in ASP.NET" under this current (Programming: Visual Basic.NET) topic.
Rating: (You must be logged in to vote)