Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out size of session in ASP.NET from web application?

Tags:

How to find out size of session in ASP.NET from web application?

like image 466
GrZeCh Avatar asked Oct 13 '08 15:10

GrZeCh


People also ask

What is the size of session?

You can store as much data as you like within in sessions. All sessions are stored on the server. The only limits you can reach is the maximum memory a script can consume at one time, which by default is 128MB.

What is session state in ASP.NET with example?

ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session. By default, ASP.NET session state is enabled for all ASP.NET applications.


1 Answers

If you're trying to get the size of Session during runtime rather than in debug tracing, you might want to try something like this:

long totalSessionBytes = 0;
BinaryFormatter b = new BinaryFormatter();
MemoryStream m;
foreach(var obj in Session) 
{
  m = new MemoryStream();
  b.Serialize(m, obj);
  totalSessionBytes += m.Length;
}

(Inspired by http://www.codeproject.com/KB/session/exploresessionandcache.aspx)

like image 63
ddc0660 Avatar answered Oct 21 '22 13:10

ddc0660