Reputation: 801
If I have sessions backed by SQL Server and run a command sequence like
HttpContext.Current.Session['user']
HttpContext.Current.Session['user']
Will this make 2 requests to the session DB table to fetch the value, or does asp.net do anything special with the Session object to prevent multiple DB hits?
Upvotes: 1
Views: 127
Reputation: 6462
Definitely YES.
I have SQL server session state setup and i ran Profiler on it. And could clearly see optimized DB calls. If fact there are optimizations for getting multiple session items in one shot.
Like the below code will also result in SINGLE optimized set of calls (Note: Its not a plain single DB call to get session item)
HttpContext.Current.Session['user']
HttpContext.Current.Session['userTwo']
NOTE: Tested in .NET 4
You can implement your own session state provider if you need. http://msdn.microsoft.com/en-us/library/ms178587.aspx
Upvotes: 1