Hi,
I am persisting the viewstate for each page into the Cache object, below is
shown my methods for saving and loading:
I am able to save the viewstate to the cache and most times I can load it
ok, however it seems that every now and again it fails to Deserialize the
viewstate.
My Application pool is set to shutdown after 180mins of idle.
IIS6.0 W2K3 SVR
TIA
MattC
private string ViewStateCacheKey
{
get{ return "VIEWSTATE_" + Request.UserHostAddress; }
}
protected override void SavePageStateToPersistenceMedium(object viewState)
{
LosFormatter oLosFormatter = new LosFormatter();
StringWriter oStringWriter = new StringWriter();
oLosFormatter.Serialize(oStringWriter, viewState);
string str = this.ViewStateCacheKey + "_" + Guid.NewGuid().ToString();
try
{
Cache.Insert(str, //key
oStringWriter.ToString(), //value
null, //dependency
Cache.NoAbsoluteExpiration, //no absolute expiration
new TimeSpan(0,0,Session.Timeout + 10,0,0), //sliding expiration
Seesion timeout
CacheItemPriority.High,
onRemove); //call back on removal
}
catch(Exception e)
{
throw new Exception("Failed to store viewstate in Cache", e);
}
}
RegisterHiddenField("__VIEWSTATE_KEY", str);
RegisterHiddenField("__VIEWSTATE", String.Empty);
}
protected override object LoadPageStateFromPersistenceMedium()
{
object viewstate = null;//return viewstate
LosFormatter oLosFormatter = new LosFormatter();
string str = Request.Form["__VIEWSTATE_KEY"];
try
{
viewstate = oLosFormatter.Deserialize(Cache[str].ToString());//cache
}
catch(Exception e)
{
Events.WriteToLog("Failed to deserialize ViewState '" + str +"'
from cache: " + e.Message);//system event log
}
return viewstate;
} 3 1924
At the 180 minute mark, the pool is recycled and the app domain is unloaded.
Variables and objects belonging to that application domain are lost. Your
viewstate may still be there, but the cache values are gone.
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------
"MattC" <m@m.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... Hi,
I am persisting the viewstate for each page into the Cache object, below is shown my methods for saving and loading:
I am able to save the viewstate to the cache and most times I can load it ok, however it seems that every now and again it fails to Deserialize the viewstate.
My Application pool is set to shutdown after 180mins of idle.
IIS6.0 W2K3 SVR
TIA
MattC
private string ViewStateCacheKey { get{ return "VIEWSTATE_" + Request.UserHostAddress; } }
protected override void SavePageStateToPersistenceMedium(object viewState) { LosFormatter oLosFormatter = new LosFormatter(); StringWriter oStringWriter = new StringWriter(); oLosFormatter.Serialize(oStringWriter, viewState); string str = this.ViewStateCacheKey + "_" + Guid.NewGuid().ToString();
try { Cache.Insert(str, //key oStringWriter.ToString(), //value null, //dependency Cache.NoAbsoluteExpiration, //no absolute expiration new TimeSpan(0,0,Session.Timeout + 10,0,0), //sliding expiration Seesion timeout CacheItemPriority.High, onRemove); //call back on removal } catch(Exception e) { throw new Exception("Failed to store viewstate in Cache", e); }
}
RegisterHiddenField("__VIEWSTATE_KEY", str); RegisterHiddenField("__VIEWSTATE", String.Empty);
}
protected override object LoadPageStateFromPersistenceMedium() {
object viewstate = null;//return viewstate LosFormatter oLosFormatter = new LosFormatter(); string str = Request.Form["__VIEWSTATE_KEY"];
try { viewstate = oLosFormatter.Deserialize(Cache[str].ToString());//cache } catch(Exception e) { Events.WriteToLog("Failed to deserialize ViewState '" + str +"' from cache: " + e.Message);//system event log }
return viewstate;
}
Also, UserHostAddress isn't guaranteed to be unique per visitor...namely
those who sit behind a proxy (increasingly popular). I would expect strange
behaviour if two users from behind the same proxy visit your application.
This is likely why sessions are prefered for server-side viewstate than
cache.
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... At the 180 minute mark, the pool is recycled and the app domain is
unloaded. Variables and objects belonging to that application domain are lost. Your viewstate may still be there, but the cache values are gone.
-- Regards, Alvin Bruney [MVP ASP.NET]
[Shameless Author plug] The Microsoft Office Web Components Black Book with .NET Now Available @ http://www.lulu.com/owc ----------------------------------------------------------
"MattC" <m@m.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... Hi,
I am persisting the viewstate for each page into the Cache object, below is shown my methods for saving and loading:
I am able to save the viewstate to the cache and most times I can load
it ok, however it seems that every now and again it fails to Deserialize
the viewstate.
My Application pool is set to shutdown after 180mins of idle.
IIS6.0 W2K3 SVR
TIA
MattC
private string ViewStateCacheKey { get{ return "VIEWSTATE_" + Request.UserHostAddress; } }
protected override void SavePageStateToPersistenceMedium(object
viewState) { LosFormatter oLosFormatter = new LosFormatter(); StringWriter oStringWriter = new StringWriter(); oLosFormatter.Serialize(oStringWriter, viewState); string str = this.ViewStateCacheKey + "_" + Guid.NewGuid().ToString();
try { Cache.Insert(str, //key oStringWriter.ToString(), //value null, //dependency Cache.NoAbsoluteExpiration, //no absolute expiration new TimeSpan(0,0,Session.Timeout + 10,0,0), //sliding expiration Seesion timeout CacheItemPriority.High, onRemove); //call back on removal } catch(Exception e) { throw new Exception("Failed to store viewstate in Cache", e); }
}
RegisterHiddenField("__VIEWSTATE_KEY", str); RegisterHiddenField("__VIEWSTATE", String.Empty);
}
protected override object LoadPageStateFromPersistenceMedium() {
object viewstate = null;//return viewstate LosFormatter oLosFormatter = new LosFormatter(); string str = Request.Form["__VIEWSTATE_KEY"];
try { viewstate =
oLosFormatter.Deserialize(Cache[str].ToString());//cache } catch(Exception e) { Events.WriteToLog("Failed to deserialize ViewState '" + str
+"' from cache: " + e.Message);//system event log }
return viewstate;
}
Guys,
The viewstate not being found is happening at times well within the 180min
mark. The proxy point is well taken and may be something to consider,
however, this is an Intranet app and so does not suffer with this.
I think I have found my answer. It lies in the priority I gave the cache
items.
CacheItemPriority.High
I think as the worker process grew with all the postbacks storing new
viewstate ASP.NET removed some entries to free resources.
As a test I have set this to NotRemovable and am relying on the expiration
to remove it.
MattC
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:ui*************@TK2MSFTNGP15.phx.gbl... Also, UserHostAddress isn't guaranteed to be unique per visitor...namely those who sit behind a proxy (increasingly popular). I would expect strange behaviour if two users from behind the same proxy visit your application. This is likely why sessions are prefered for server-side viewstate than cache.
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... At the 180 minute mark, the pool is recycled and the app domain is unloaded. Variables and objects belonging to that application domain are lost. Your viewstate may still be there, but the cache values are gone.
-- Regards, Alvin Bruney [MVP ASP.NET]
[Shameless Author plug] The Microsoft Office Web Components Black Book with .NET Now Available @ http://www.lulu.com/owc ----------------------------------------------------------
"MattC" <m@m.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... > Hi, > > I am persisting the viewstate for each page into the Cache object, > below > is shown my methods for saving and loading: > > I am able to save the viewstate to the cache and most times I can load it > ok, however it seems that every now and again it fails to Deserialize the > viewstate. > > My Application pool is set to shutdown after 180mins of idle. > > IIS6.0 W2K3 SVR > > > TIA > > MattC > > private string ViewStateCacheKey > { > get{ return "VIEWSTATE_" + Request.UserHostAddress; } > } > > protected override void SavePageStateToPersistenceMedium(object viewState) > { > LosFormatter oLosFormatter = new LosFormatter(); > StringWriter oStringWriter = new StringWriter(); > oLosFormatter.Serialize(oStringWriter, viewState); > string str = this.ViewStateCacheKey + "_" + Guid.NewGuid().ToString(); > > try > { > Cache.Insert(str, //key > oStringWriter.ToString(), //value > null, //dependency > Cache.NoAbsoluteExpiration, //no absolute expiration > new TimeSpan(0,0,Session.Timeout + 10,0,0), //sliding expiration > Seesion timeout > CacheItemPriority.High, > onRemove); //call back on removal > } > catch(Exception e) > { > throw new Exception("Failed to store viewstate in Cache", e); > } > > } > > RegisterHiddenField("__VIEWSTATE_KEY", str); > RegisterHiddenField("__VIEWSTATE", String.Empty); > > } > > protected override object LoadPageStateFromPersistenceMedium() > { > > object viewstate = null;//return viewstate > LosFormatter oLosFormatter = new LosFormatter(); > string str = Request.Form["__VIEWSTATE_KEY"]; > > try > { > viewstate = oLosFormatter.Deserialize(Cache[str].ToString());//cache > } > catch(Exception e) > { > Events.WriteToLog("Failed to deserialize ViewState '" + str +"' > from cache: " + e.Message);//system event log > } > > return viewstate; > > } >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bill H |
last post by:
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all...
|
by: Angel |
last post by:
I am saving items in the cache in my code behind. By setting these items with
an expiration are these items only available for the page its being set or
throughout the application? My next question...
|
by: Guadala Harry |
last post by:
I want to create a STATIC method that removes all items from the Cache.
Questions:
1. Is a safe thing to do (any threading issues?)
2. Is the following code a good way to get the job done -...
|
by: Christopher |
last post by:
In one of our ASP.NET Pages, we are starting a new background thread that we
do not need to go and get any status on or use after the page finishes. The
thread merely does some background stuff on...
|
by: W. Jordan |
last post by:
Hello,
I would like to instantiate multiple Cache instances within my
web application, for instance, one for database related items,
one for application configuration items, one for user...
| |
by: Adam |
last post by:
On an xp machine, the caching works as expected. I have deployed to a win2k
server, and an item I add to the cache expires almost immediately some times
and in under a minute in other times. The...
|
by: Stan SR |
last post by:
Hi,
Some newbie questions.. :-)
First, what is the namespace to use for the Cache class ?
When I use this bit of code I get an error
if (Cache==null) Cache.Insert("myUserList",userlist);...
|
by: poolieweb |
last post by:
I have created a custom user control which creates a ASPxMenu ( Same
fucntion as standard menu control) from data retreved from a webservice
(Reporting Services) which deals with user access. This...
|
by: BizWorld |
last post by:
I am trying to cache a full DROP Down that can have lot of values. so
i have 500 site users hitting a page in a second. i need to cache some
controls that does not change quite often during the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |