Thursday, March 22, 2012

session variables

When do we use HTTPcontext.current.session and just session?

Thanks,

Prasad

Generally, when the class doesn't inheirit a class like System.Web.UI.Page that defines access to the Session object that way. Either way will accomplish the same thing.

True.

However, avoid using session if possible. Think of it more like a backward compatibility feature...

I think in most cases you'll find that you could be using the Cache object instead of session, which is more flexible and better performant (session reads & writes once per every page load).


Why should you avoid using Sessions? They are still very popular and not deprecated in any way. Cache works the same way, it read and write it during the page load to the cache manager.

You use HttpContext.Current.Session when you want to access the session object from the class library and you use Session when you are accessing the session object from the page. Session is still valid and is used frequently in many applications. The difference between Session and Cache is that Session is per user and Cache is global.

0 comments:

Post a Comment