CopyCode The Code is as follows: public class xvpage: Page
{
Static private directoryinfo _ DIR;
Private directoryinfo dir
{
Get
{
If (_ DIR = NULL)
{
_ DIR = new directoryinfo (path. Combine (appdomain. currentdomain. basedirectory, "app_data "));
If (! _ DIR. exists)
_ DIR. Create ();
_ DIR = new directoryinfo (path. Combine (_ DIR. fullname, "viewstate "));
If (! _ DIR. exists)
_ DIR. Create ();
}
Return _ DIR;
}
}
Protected override object loadpagestatefrompersistencemedium ()
{
Pagestatepersister PS = This. pagestatepersister;
PS. Load ();
If (PS. controlState! = NULL)
PS. controlState = antiserialization (string) PS. controlState );
If (PS. viewstate! = NULL)
PS. viewstate = antiserialization (string) PS. viewstate );
Return new pair (PS. controlState, PS. viewstate );
}
Protected override void savepagestatetopersistencemedium (object state)
{
Pagestatepersister PS = This. pagestatepersister;
If (State is pair)
{
Pair pair = (pair) State;
PS. controlState = pair. first;
PS. viewstate = pair. Second;
}
Else
{
PS. viewstate = State;
}
If (PS. controlState! = NULL)
PS. controlState = antiserialization (PS. controlState );
If (PS. viewstate! = NULL)
PS. viewstate = antiserialization (PS. viewstate );
PS. Save ();
}
Private object antiserialization (string stateid)
{
String statestr = (string) cache [stateid];
String file = path. Combine (dir. fullname, stateid );
If (statestr = NULL)
Statestr = file. readalltext (File );
Else
Cache. Remove (stateid );
Return new objectstateformatter (). deserialize (statestr );
}
Private string antiserialization (Object OBJ)
{
String value = new objectstateformatter (). serialize (OBJ );
String stateid = (datetime. Now. ticks + (long) value. gethashcode (). tostring (); // generates a discrete ID number.
File. writealltext (path. Combine (dir. fullname, stateid), value );
Cache. insert (stateid, value );
Return stateid;
}
Protected override void onUnload (eventargs E)
{
Base. onUnload (E );
Datetime dt = datetime. Now. addminutes (-20 );
Foreach (fileinfo fl in Dir. getfiles ())
If (FL. lastaccesstime <DT)
Try
{
Fl. Delete ();
}
Catch
{
}
}
}
you only need to inherit xvpage from the background of the page.
Public partial class index_content: xvpage