Domanda

I need to inspect the session size at certain moments. How can I achive this?

I have to tried to create a custom tab in Glimpse but the session object is always null:

public override object GetData(Glimpse.Core.Extensibility.ITabContext context)  
{
    var result = new List<string[]> { new[] { "Object", "Number of bytes" } };

    HttpContextBase context1 = context.GetHttpContext();
    HttpSessionStateBase session = context1.Session;

    if (session != null)
    {
        long totalSessionBytes = 0;
        BinaryFormatter b = new BinaryFormatter();
        MemoryStream m;
        foreach (var obj in session)
        {
            m = new MemoryStream();
            b.Serialize(m, obj);
            result.Add(new[] { obj.ToString(), m.Length.ToString() });
            totalSessionBytes += m.Length;
        }

        result.Add(new[] { "Total", totalSessionBytes.ToString() });
    }
    else
    {
        result.Add(new[] { "Session", "Null" });
    }
    return result; 
}

I also tried this:

https://github.com/jasonrclark/Glimpse/commit/89416a7e7934d98a02839fc7976a288ca18f6d60

But I can't find any IGlimpsePlugin interface.

È stato utile?

Soluzione

Depending on how you implemented your tab

  • implementing the Glimpse.Core.Extensibility.ITab
  • inheriting from Glimpse.Core.Extensibility.TabBase, Glimpse.Core.Extensibility.TabBase<T> or Glimpse.AspNet.Extensibility.AspNetTab

you must make sure that you implement/override the RuntimeEvent ExecuteOn property so that it runs at RuntimeEvent.BeginSessionAccess or RuntimeEvent.EndSessionAccess

because by default it is RuntimeEvent.EndRequest which is too late for Session access

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top