Profile Memory Usage of Session State ASP.Net

前端 未结 2 645
灰色年华
灰色年华 2020-12-29 00:15

I\'m trying to figure out the size of a particular session state. On one of our heavy pages (lots of data in a table) it gets progressively slower. The issue is resolved by

2条回答
  •  孤独总比滥情好
    2020-12-29 00:57

    Measure it:

    int totalBytes;
    var formatter = new BinaryFormatter();
    for(int i = 0; i < Session.Count; i++)
    {
        using (var stream = new MemoryStream())
        {
            formatter.Serialize(stream, Session[i]);
            stream.Flush();
            totalBytes += stream.Length;
        }
    }
    

    Also I believe that if you enable tracing it will show you some details about the session (not sure about this, never tried it myself).

提交回复
热议问题