ASP.NET Podcast Show #30 - Minimizing the ASP.NET ViewState Part #2
Subscribe - The Wally Way to do things. Cool. Hip. Get iTunes or iPodder.
Download – The
Check us out on the ASP.NET Site.
Show Notes:
Scott Allen isn’t the only person that needs more Wally. We got an email from Bruce Dickinson. He says “I got a fever, and the only prescription is more Wally!” He has got to have “more Wally.” You need to listen to the ASP.NET Podcast.
Correction from the previous podcast. DnD in Atlas does work, its just not documented well at this moment. Thanks to Wilco Bauwer.
As we get into the Holiday Season, whether it is Christmas, Hanukah, Kwanza or something else, we need to look at how we act towards each other.
As some of you know, there has been a lot of public discussion back and forth in the .NET community in South Carolina. I have had some amount of a little bit of knowledge about this as one of the people involved is a buddy of mine and worked on our ADO.NET book. As I watched the issues play out, I looked at myself.
Hard for technology people to work with each other.
We strike out at each other.
I’ve done it.
I’ve had it done to me.
How should we act? We need to be open and honest without being rude to each other. Learn how to work together. Learn how to pump people up instead of pushing people down. There are plenty of people that want to push you down.
SavePageToPersistenceMedium code:
string strViewStateKey = this.CreateFileName();
string FileDir = GetConfigInformation();
CleanUpInfo cui = new CleanUpInfo();
cui.Dir = FileDir;
cui.TimeOut = 60*60;
ThreadPool.GetAvailableThreads(out iMaxWorkerThrds, out iMaxIOThrds);
if (iMaxWorkerThrds > giMinimumThreads)
{
ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(CleanUpFileDirectory),cui);
Thread.Sleep(0);
}
RegisterHiddenField("__VIEWSTATE_KEY", strViewStateKey);
RegisterHiddenField("__VIEWSTATE", String.Empty);
strViewStateKey = System.IO.Path.Combine(FileDir, strViewStateKey);
LosFormatter los = new LosFormatter();
StringWriter writer = new StringWriter();
// serialize the view state into a base-64 encoded string
los.Serialize(writer, viewState);
// save the string to disk
StreamWriter sw = File.CreateText(strViewStateKey);
sw.Write(writer.ToString());
sw.Close();
LoadPageStateFromPersistenceMedium:
string ViewStateFile = System.IO.Path.Combine(Server.MapPath(GetConfigInformation()), Request.Form["__VIEWSTATE_KEY"]);
LosFormatter los = new LosFormatter();
StreamReader reader= File.OpenText(ViewStateFile);
string viewStateString = reader.ReadToEnd();
reader.Close();
obj = los.Deserialize(viewStateString);
Cleanup Routine:
int i = 0;
CleanUpInfo cui = (CleanUpInfo)obj;
string strDir = cui.Dir;
double dblTimeOut = -cui.TimeOut;
DirectoryInfo di = new System.IO.DirectoryInfo(strDir);
FileSystemInfo[] fileInfo;
fileInfo = di.GetFileSystemInfos();
for(i = 0 ; i < fileInfo.Length; i++)
{
try
{
if ((fileInfo[i].CreationTime < (DateTime.Now.AddSeconds(dblTimeOut))&&
(fileInfo[i].Name != gErrorName)))
{
fileInfo[i].Delete();
}
}
catch(System.UnauthorizedAccessException uaeExc)
{
LogError(uaeExc);
}
finally
{
}
}
private static void LogError(System.UnauthorizedAccessException uaeExc)
{
LogError((System.Exception)uaeExc);
}
private static void LogError(System.Exception sysExc)
{
string FileDir = GetConfigInformation();
string strErrorLog = gErrorName;
string strFileName = System.IO.Path.Combine(FileDir, strErrorLog);
StreamWriter sw = new StreamWriter(strFileName, true);
sw.WriteLine("Time: " + DateTime.Now.ToString() + ", Exception message: " + sysExc.Message.ToString());
sw.Close();
sw = null;
}