开发者

Can I store a Scripting Dictionary in a session variable?

I have a classic ASP site where I create a dictionary when the user logs in and then stores that dictionary in a session variable like so...

dim objDict
set objDict = server.createobject("scripting.dictionary")
' processing here开发者_如何学编程 to fill dictionary
set session("user") = objDict

That all works fine and dandy but when I navigate to another page and try to access a value from the stored dictionary like this...

session("user").item("id")

I get the following error...

error '80020009'

Can anyone tell me if I'm accessing the stored dictionary incorrectly? Is storing the dictionary object in a session variable a bad/wrong thing to do?

Thanks


The error you are getting is a remote procedure call error. I can't explain why you get this error or why extracting into a local variable fixes it.

However I can tell that its really bad idea. When you store an object such as this in the Session object you create an affiliation between the current thread executing the script and the session. As result all subsequent requests for that session must now be handle only by this specific thread. If that thread happens to be busy handling someone elses request the sessions request is queued even if there are plenty of available work threads that could be used. Hence storing an object in the Session can significantly damage the scalability of the app.

I'd also question the wisdom of storing a Dictionary in something which is already a dictionary?

Why not just user :-

Dim userID : userID = Session("user_id")

Where anything you would normally have stored in the "user" dictionary, such as "id", would simply have the prefix "user_" and stored direcly in the Session?


Have you tried in your code doing something like the following when you want to access it?

Dim objDict
Set objDict = session("user") 
Response.Write objDict("id")

Try that and see if it works. I wouldn't think this would be necessary but Classic ASP wasn't exactly the most robust language. What you want to do should be workable, since the Session object simply stores objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜