开发者

Storing XML into ASP Session variable

On my site I will have a number of session variables that I will need to access on every page load. Instead of calling back to the DB over and over, I want to save this info into session variables.

I don't want to create 30 different Session variables, so I am thinking about storing similar variables into an xml document, then into a Session variable. Like this...

Session("UserRights") = "<xml><canEdit>1</canEdit><foo>bar</foo></xml>"
Set oDOM = Server.CreateObject("MSXML2.FreeThreadDOMDocument.3.0") 'etc...

Is this a good idea? Will I take a bigger performance hit by parsing this xmlString on each page load? I know I shouldn't store an Object (like a dictionary) into a session (that's why I am choosing xml string) but I am in need of a开发者_如何学C new approach...

The website is currently written in classic asp, but we are slowing migrating to asp.net using (aspcompat="true") This is not the best migration approach but we have deadlines we need to meet.

Thanks for the advice


Your session variables are stored in a database, too, so you're not necessarily saving a database hit. And parsing does take time (you'd have to measure it to see if it is noticeable).

I have a similar situation where I have contact information for the user that has to move from page to page. Once I retrieve it from the database I put it in session vars that look like Session("user.first-name"), Session("user.last-name"), Session("user.address"), etc. There's one particular variable ("user.id") I test to make sure the session hasn't expired. So if IsEmpty(Session("user.id")) or Session("user.id") = "" I know the session vanished and I need to account for that. While the use of "dot notation" in my session variable names is meaningless, it does help me see that all those variables are related, as opposed to having a dozen or more names like "first-name", "last-name", etc. I have one function that loads all those variables and another that destroys them when I'm done with them, which helps manage the complexity of having lots of session variables.

I have other situations where I store a number of bits of information about a user in a database table and have a function I call at the top of every page to give me access to that info on the page. This works OK too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜