Can I store a Scripting Dictionary in a session variable?

十年热恋 提交于 2019-12-01 23:37:39

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.

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!