0

I store data in

    HttpContext.Current.Application.Add(appKey, value);

And read data by this one:

  HttpContext.Current.Application[appKey];

This has the advantage for me that is using a key for a value but after a short time (about 20 minutes) it does not work, and I can not find [appKey],because the application life cycle in iis data will lose. i want to know is that another way to store my data by key and value? i do not want sql server,file,... and want storing data on server not on client

i store users some data in it.

thanks for your helping

gtgaxiola
  • 9,241
  • 5
  • 42
  • 64
motevalizadeh
  • 5,244
  • 14
  • 61
  • 108

4 Answers4

3

Since IIS may recycle and throw away any cache/memory contents at any time, the only way you will get data persisted is to store it outside IIS. Some examples are; (and yes, I included the ones you stated you didn't want just to have the list a bit more complete, feel free to skip them)

  • A SQL database (there are quite a few free ones if the price is prohibitive)
  • A NoSQL database (same thing there, quite a few free ones and usually simpler to use for key/value)
  • File (which you also stated you didn't want)
  • Some kind of external memory cache, a'la AppFabric cache or memcached.
  • Cookies (somewhat limited in size and not secure in any way by default)
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 2
    +1, for the real answer to this question. The OP already asked this question and I told him that unless he persists this information out of the AppDomain he will lose it when IIS recycles the application but I guess he wanted a second opinion on it. – Darin Dimitrov Sep 17 '12 at 18:14
0

you could create a persistent cookie on the user's machine so that the session doesn't expire, or increase the session timeout to a value that would work better for your situation/users

How to create persistent cookies in asp.net?

Session timeout in ASP.NET

Community
  • 1
  • 1
wes
  • 265
  • 1
  • 11
  • Session won't help if this session is stored in-memory (default) and if IIS recycles the application. No matter how large you have set the timeout if the AppDomain gets recycled everything you have stored inside the session is lost. Cookies could be indeed a solution but notice that they should be used to store non sensitive per-user data, whereas the OP is using the Application scope which is global, not per-user. – Darin Dimitrov Sep 17 '12 at 18:12
  • @DarinDimitrov but the OP is asking about storing user's data. Why would you prefer to store in application scope vice session scope for user data? – wes Sep 17 '12 at 18:15
  • where did the OP state that he wants to store user data? – Darin Dimitrov Sep 17 '12 at 18:16
  • "i store users some data in it." – wes Sep 17 '12 at 18:17
  • Oh well, you are right. Then I guess the OP misunderstands the difference between those 2 scopes because he is using Application state. – Darin Dimitrov Sep 17 '12 at 18:18
0

You're talking about persisting data beyond the scope of a session. So you're going to have to use some form of persistent storage (Database, File, Caching Server).

Have you considered using AppFabric. It's actually pretty easy to implement. You could either access it directly from your code using the nuget packages, or you could just configured it as a session store. (I think) doing the latter would mean you'd get rid of the session timeout issue.

Antony Scott
  • 21,690
  • 12
  • 62
  • 94
0

Do you understand that whatever you decide to store in Application, will be available for all users in your application?

Now regarding your actual question, what kind of data do you plan on storing? If its user sensitive data, then it probably makes sense to store it in the session. If it's client specific and it doesn't contain any sensitive information, than cookies is probably a reasonable way forward.

If it is indeed an application wide data and it must be the same for every user of your application, then you can make configuration changes to make sure that it doesn't expiry after 20 minutes.