Static is REALLY Static!

P

Paul W

In a standalone module (VB) behind my asp.net application, I have a couple
of utility routines that do a simple (fixed) data-retrieval (eg. "select
permissions from tblusers where userid=" & thisuser.

I figured I'd be smart and save multiple db calls for the same page request
by doing:

Function GetPerms() as string
Static myperms as string
if myperms="" then
{get value from db}
myperms=valueFromDb 'store the retrieved data in a Static variable for
use on the next request
else
GetPerms=myperms
endif
End Function

Well, blow me down, I find that the static values persist across different
page requests - even across multiple browser-sessions!!!

Can someone please enlighten me as to what's goin on here?

Thanks,
Paul.
 
K

Karl Seguin

There isn't too much enlightening to do...that's what static is.

It isn't tied to a page request, or a specific user...instead it's tied to
the application domain...You can read more from:
http://www.panopticoncentral.net/archive/2004/04/19/964.aspx

Without knowing much more about what ur doing, I think you'd typically you'd
use something like the HttpCache or Session for what you are trying to
do...

Karl
 
D

drjones

Hi,


for some reason static variables in asp.net have application-wide scope.
It's almost the same as Application("myperms"). You could rewrite your
code:


Private myperms as string
Function GetPerms() as string
if myperms="" then
{get value from db}
myperms=valueFromDb 'store the retrieved data in a Static variable for
use on the next request
else
GetPerms=myperms
endif
End Function




Dr. Jones
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top