i have a code in which i store some values in the session variable. my session timeout is set to 30 minutes.
now after 30 minutes the value is lost from the session variable if the page is left unused for 30 minutes. and when trying to access the value, the value returned is null.
now i dont want this to happen even after for a long period of time, i want that value should remain there. Is there an alternative to this.
As suggested above cookies are best way for your requirement but cookies come with size limitation. Dont really know what you are trying to achieve but consider using Application object too. You can save the value in application object. The value stored
in applicaton object remains in the memory till the application is running.
But please go through the following link before working with application objects:
thanks all for your replies, but i have already gone through all these stuffs.
let me explain wat i am tryin to achieve. Its pretty long, but i will go by it now.
i am making a shopping cart.
now the usage....
user(guest user or anonymous) comes online, select products, adds it to cart, the product is added to cart and the cart detail is stored in the DB along with the unique key identifying this particular user and his cart items. all other user's cart items
are differentiated based upon this particular unique id of the user taken from Request.AnonymousUserID property.
so every time the cart items are fetched i get only those rows from the table which have this AnonymousUserID.
now everything works fine, but when the site is left for few minutes, untouched or unused, the AnonymousUserID is lost. and the application is unable to determine which user is accesing the webpage and hence is unable to retrieve cart items from the Cart
table based upon the UniqueID which this user was assigned when he first visited the site. This creates a problem and the user loses all his cart items one he lefts the application for few minutes.
How i am currently evading it, is by setting the Application Pool Idle Timeout on the server to 20 minutes, hence the UniqueID is maintained upto 20 minutes, but not more. if i set it to 60 minutes, it is maintained upto 60 minutes as the pool is not recycled.
this is causing resource problem on server, and i dont want to do it, so what can i do to make it work, coz i see on many sites that the Guest cart remains for very long time even if the site is left untouched for hours. what am i missing.
Hi, with your requirement, it is better to use cookie, you can set the cookie expire time to a long time, for example: one month. In this way, the cookie will persists during this month. There is an example on the following link, you can refer to it:
mohammed.kam...
Member
139 Points
92 Posts
Persist Session Value or Replacement For Session
Aug 07, 2012 08:49 PM|LINK
Hi,
i have a code in which i store some values in the session variable. my session timeout is set to 30 minutes.
now after 30 minutes the value is lost from the session variable if the page is left unused for 30 minutes. and when trying to access the value, the value returned is null.
now i dont want this to happen even after for a long period of time, i want that value should remain there. Is there an alternative to this.
note: the session is used across multiple pages
thanks
OWDARO
BrockAllen
All-Star
27434 Points
4891 Posts
MVP
Re: Persist Session Value or Replacement For Session
Aug 07, 2012 08:50 PM|LINK
Use a database or some other state management approach.
https://brockallen.wordpress.com/2012/04/07/think-twice-about-using-session-state/
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Allen Li - M...
Star
10411 Points
1196 Posts
Re: Persist Session Value or Replacement For Session
Aug 09, 2012 07:23 AM|LINK
Hi, based on your requirement, I suggest using Cookie:
http://msdn.microsoft.com/en-us/library/ms178194.aspx
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
GaurangNaik
Contributor
2066 Points
495 Posts
Re: Persist Session Value or Replacement For Session
Aug 09, 2012 08:50 PM|LINK
Hi,
As suggested above cookies are best way for your requirement but cookies come with size limitation. Dont really know what you are trying to achieve but consider using Application object too. You can save the value in application object. The value stored in applicaton object remains in the memory till the application is running.
But please go through the following link before working with application objects:
http://msdn.microsoft.com/en-us/magazine/cc301579.aspx
http://www.dotnetspider.com/tutorials/AspNet-Tutorial-39.aspx
GauranG
MahadTECH
Star
8976 Points
1659 Posts
Re: Persist Session Value or Replacement For Session
Aug 10, 2012 12:15 AM|LINK
M.Kamran Azam, aoa,
I'll prefer you to use Database. Store value in Database and read from there,, and also you can use cookie is ideal for this situation..
Or Im giving you an idea.. about HiddenField on every page. to restore the Session
Store Value in Session also in HiddenField.
if(Session["yourKey"] == null)
{
Session["yourKey"] = HiddenField1.Value;
}
when ever session will be null it will restore from HiddenField.
So, you have 3 ways Cookies, DB, Session/HiddenField Merge.
Good Luck`
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
mohammed.kam...
Member
139 Points
92 Posts
Re: Persist Session Value or Replacement For Session
Aug 10, 2012 12:42 AM|LINK
thanks all for your replies, but i have already gone through all these stuffs.
let me explain wat i am tryin to achieve. Its pretty long, but i will go by it now.
i am making a shopping cart.
now the usage....
user(guest user or anonymous) comes online, select products, adds it to cart, the product is added to cart and the cart detail is stored in the DB along with the unique key identifying this particular user and his cart items. all other user's cart items are differentiated based upon this particular unique id of the user taken from Request.AnonymousUserID property.
so every time the cart items are fetched i get only those rows from the table which have this AnonymousUserID.
now everything works fine, but when the site is left for few minutes, untouched or unused, the AnonymousUserID is lost. and the application is unable to determine which user is accesing the webpage and hence is unable to retrieve cart items from the Cart table based upon the UniqueID which this user was assigned when he first visited the site. This creates a problem and the user loses all his cart items one he lefts the application for few minutes.
How i am currently evading it, is by setting the Application Pool Idle Timeout on the server to 20 minutes, hence the UniqueID is maintained upto 20 minutes, but not more. if i set it to 60 minutes, it is maintained upto 60 minutes as the pool is not recycled.
this is causing resource problem on server, and i dont want to do it, so what can i do to make it work, coz i see on many sites that the Guest cart remains for very long time even if the site is left untouched for hours. what am i missing.
OWDARO
Allen Li - M...
Star
10411 Points
1196 Posts
Re: Persist Session Value or Replacement For Session
Aug 10, 2012 07:41 AM|LINK
Hi, with your requirement, it is better to use cookie, you can set the cookie expire time to a long time, for example: one month. In this way, the cookie will persists during this month. There is an example on the following link, you can refer to it:
http://www.codeproject.com/Articles/93639/Simple-Shopping-Cart-Basket-User-Control-using-ASP
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
nelson123
Member
21 Points
26 Posts
Re: Persist Session Value or Replacement For Session
Aug 10, 2012 03:30 PM|LINK
you can dissable the session time out from web.config or global.asa or
You can use different objects of session management like application object,cache object, database,cookies etc.
Mark as answer if you find the post useful
Web Developer
Mumbai