Trying to understand System.Web.UI.SessionPageStatePersister

J

Jeremy Chapman

I am thinking of implementing System.Web.UI.SessionPageStatePersister as a
method of storing viewstate in the session. Before I do, I am browsing
threw the class's code using reflector just to get an understanding of
performance/memory hits on the server. I've attached the code below, and
my understanding of it is less that what I like. Is there anyone here with
a more familiar knowledge of how it works? I'm wondering how it cleans up
old view state, etc.

public override void Load()
{
if (base.Page.RequestValueCollection != null)
{
try
{
string text1 = base.Page.RequestViewStateString;
string text2 = null;
bool flag1 = false;
if (!string.IsNullOrEmpty(text1))
{
Pair pair1 = (Pair)
Util.DeserializeWithAssert(base.StateFormatter, text1);
if ((bool) pair1.First)
{
text2 = (string) pair1.Second;
flag1 = true;
}
else
{
Pair pair2 = (Pair) pair1.Second;
text2 = (string) pair2.First;
base.ControlState = pair2.Second;
}
}
if (text2 != null)
{
object obj1 = base.Page.Session["__SESSIONVIEWSTATE"
+ text2];
if (flag1)
{
Pair pair3 = obj1 as Pair;
if (pair3 != null)
{
base.ViewState = pair3.First;
base.ControlState = pair3.Second;
}
}
else
{
base.ViewState = obj1;
}
}
}
catch (Exception exception1)
{
HttpException exception2 = new
HttpException(SR.GetString("Invalid_ControlState"), exception1);
exception2.SetFormatter(new
UseLastUnhandledErrorFormatter(exception2));
throw exception2;
}
}
}



public override void Save()
{
bool flag1 = false;
object obj1 = null;
Triplet triplet1 = base.ViewState as Triplet;
if ((base.ControlState != null) || ((((triplet1 == null) ||
(triplet1.Second != null)) || (triplet1.Third != null)) && (base.ViewState
!= null)))
{
HttpSessionState state1 = base.Page.Session;
string text1 = Convert.ToString(DateTime.Now.Ticks, 0x10);
object obj2 = null;
flag1 = base.Page.Request.Browser.RequiresControlStateInSession;
if (flag1)
{
obj2 = new Pair(base.ViewState, base.ControlState);
obj1 = text1;
}
else
{
obj2 = base.ViewState;
obj1 = new Pair(text1, base.ControlState);
}
string text2 = "__SESSIONVIEWSTATE" + text1;
state1[text2] = obj2;
Queue queue1 = state1["__VIEWSTATEQUEUE"] as Queue;
if (queue1 == null)
{
queue1 = new Queue();
state1["__VIEWSTATEQUEUE"] = queue1;
}
queue1.Enqueue(text2);
SessionPageStateSection section1 =
RuntimeConfig.GetConfig(base.Page.Request.Context).SessionPageState;
int num1 = queue1.Count;
if (((section1 != null) && (num1 > section1.HistorySize)) ||
((section1 == null) && (num1 > 9)))
{
string text3 = (string) queue1.Dequeue();
state1.Remove(text3);
}
}
if (obj1 != null)
{
base.Page.ClientState =
Util.SerializeWithAssert(base.StateFormatter, new Pair(flag1, obj1));
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top