Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a new way to pass session values?

Status
Not open for further replies.

smsinger3

Programmer
Oct 5, 2000
192
US
Hello all. I am converting an intranet site from asp classic to asp.net. I'm looking for opinions about how to pass the same variables to different class modules. In classic asp we have many variables describing a user, such as logon, department, division, etc... These are Dim'd at the top of every .asp page. These variables are used in about every asp class module that is called. The scope of these variables are global even to the class modules (although, that's not the best programming style). Well, with .net, the scope of these variables change, and I need to declare them in every class module where they are used. I'm trying to find a way around this. Here are my options and brilliant ideas (sarcasm intended):
1) Put all these values in session variables. (I'm avoiding this like the plague as session variables take up memory and resources.)
2) Re-read the database in every class module to get the information. (I'm also trying to avoid database calls!)
3) Create a hash table that can be read by everyone and only extract that person's row. Since I specified "Shared", the hash table would be shared by all sessions and all users, so I would have to exract the persons information like this:
strUser = hshUsers.Item("logonid")
I would have to delete the entry in the Session_End sub when the user is finished. Basically, the hash table would be defined like this:

Public Shared hshUsers As New Hashtable()
Structure structUserVars
Dim strLogonID as String
Dim lngDeptCode as Long
Dim lngDivCode as Long
..etc..
End Structure

4) Is there another way to share variable in the same session besides these methods?

Does all of this remotely make sense?

What do you think is the best and most efficient way to do this? Your opinions are certainly appreciated!

Thanks for reading this looong message!

Steve
sms@hmbnet.com
 
ok, a few options:

1. If these are static variables, just make them constant in some module and define them Public, that way they can be accessible from anywhere.

2. If these aren't static, and you want to keep track of the user accross pages, you can either:
a) store them in viewstate BUT (heh, had a great discussion post on this a while back) its not super secure, even over https. But if you don't really care if the users jump through hoops to see the data, its a viable option.
or
b) store only the primary key information (i.e. userID) in session. That way, when you come to a page that needs to check something on that user, you can create a userobject and load it passing hte userID. This way, you don't need to store all the users info in session all the time, and you only get hte info when you need it.

Those would be the ways I'd look at it. The other option is to use a sql server db as your session variable store, but it means hitting the db more often; however, ifyou have alot of data that you need to keep track of, hitting a fast db is better than taking up huge amounts of memory/resources.

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top