M
MattC
Gents,
I have had to persist the viewstate into the Session object, however once
this was done the W3WP process' memory ramped right up and used 300MB of VM.
Below is my code, can anyone see where a leak may be. I am using the
aspnet_state to store my session info.
TIA
MattC
private string NewViewState
{
get{ return "VIEWSTATE_"; }
}
private string ViewStateKey
{
get{ return "__VIEWSTATE_KEY"; }
}
private string UniqueViewStateKey
{
get{ return NewViewState + Request.UserHostAddress + "_" +
Guid.NewGuid().ToString(); }
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
try
{
if(Conquest.ConfigurationData.ViewStateStorage ==
ViewStateStorage.Session)//if we are implementing our on server viewstate
{
string str = this.UniqueViewStateKey;
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);//serialize viewstate
into string writer
oLosFormatter = null;
Session[str] = oStringWriter.ToString(); //store in state server
oStringWriter = null;
RegisterHiddenField(ViewStateKey, str);
RegisterHiddenField("__VIEWSTATE", String.Empty);
}
else
{
base.SavePageStateToPersistenceMedium(viewState);
}
}
catch(Exception e)
{
throw new
ConquestException("PerformancePage.SavePageStateToPersistenceMedium Failed",
null, e);
}
}
protected override object LoadPageStateFromPersistenceMedium()
{
try
{
if(Conquest.ConfigurationData.ViewStateStorage ==
ViewStateStorage.Session)//if we are implementing our on server viewstate
{
object viewstate = null;//return viewstate
string str = Request.Form[ViewStateKey];
LosFormatter oLosFormatter = new LosFormatter();
if (!str.StartsWith(NewViewState)) //check the viewstate exists
{
Conquest.Events.WriteToLog("Failed to locate VIEWSTATE KEY: '" + str
+"'");
ViewStatePersistanceFailure(str);//failure
}
else//view state does exist
{
try
{
string tmp = Session[str].ToString();//get the serialize viewstate
from session
viewstate = oLosFormatter.Deserialize(tmp);//deserialize into object
oLosFormatter = null;
}
catch(Exception e)//catch all and handle gracefully
{
Conquest.Events.WriteToLog("Failed to Load ViewState from " +
Conquest.ConfigurationData.ViewStateStorage.ToString() +
" " +
ConquestException.HandleConquestException(e),System.Diagnostics.EventLogEntryType.Information);
ViewStatePersistanceFailure(str);//Response.Redirect to homepage
}
}
//return what we got from deserialized viewstate
return viewstate;
}
else //use standard viewstate
{
return base.LoadPageStateFromPersistenceMedium();
}
}
catch(Exception e)
{
throw new
ConquestException("PerformancePage.LoadPageStateFromPersistenceMedium
failed", null, e);
}
}
I have had to persist the viewstate into the Session object, however once
this was done the W3WP process' memory ramped right up and used 300MB of VM.
Below is my code, can anyone see where a leak may be. I am using the
aspnet_state to store my session info.
TIA
MattC
private string NewViewState
{
get{ return "VIEWSTATE_"; }
}
private string ViewStateKey
{
get{ return "__VIEWSTATE_KEY"; }
}
private string UniqueViewStateKey
{
get{ return NewViewState + Request.UserHostAddress + "_" +
Guid.NewGuid().ToString(); }
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
try
{
if(Conquest.ConfigurationData.ViewStateStorage ==
ViewStateStorage.Session)//if we are implementing our on server viewstate
{
string str = this.UniqueViewStateKey;
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);//serialize viewstate
into string writer
oLosFormatter = null;
Session[str] = oStringWriter.ToString(); //store in state server
oStringWriter = null;
RegisterHiddenField(ViewStateKey, str);
RegisterHiddenField("__VIEWSTATE", String.Empty);
}
else
{
base.SavePageStateToPersistenceMedium(viewState);
}
}
catch(Exception e)
{
throw new
ConquestException("PerformancePage.SavePageStateToPersistenceMedium Failed",
null, e);
}
}
protected override object LoadPageStateFromPersistenceMedium()
{
try
{
if(Conquest.ConfigurationData.ViewStateStorage ==
ViewStateStorage.Session)//if we are implementing our on server viewstate
{
object viewstate = null;//return viewstate
string str = Request.Form[ViewStateKey];
LosFormatter oLosFormatter = new LosFormatter();
if (!str.StartsWith(NewViewState)) //check the viewstate exists
{
Conquest.Events.WriteToLog("Failed to locate VIEWSTATE KEY: '" + str
+"'");
ViewStatePersistanceFailure(str);//failure
}
else//view state does exist
{
try
{
string tmp = Session[str].ToString();//get the serialize viewstate
from session
viewstate = oLosFormatter.Deserialize(tmp);//deserialize into object
oLosFormatter = null;
}
catch(Exception e)//catch all and handle gracefully
{
Conquest.Events.WriteToLog("Failed to Load ViewState from " +
Conquest.ConfigurationData.ViewStateStorage.ToString() +
" " +
ConquestException.HandleConquestException(e),System.Diagnostics.EventLogEntryType.Information);
ViewStatePersistanceFailure(str);//Response.Redirect to homepage
}
}
//return what we got from deserialized viewstate
return viewstate;
}
else //use standard viewstate
{
return base.LoadPageStateFromPersistenceMedium();
}
}
catch(Exception e)
{
throw new
ConquestException("PerformancePage.LoadPageStateFromPersistenceMedium
failed", null, e);
}
}