开发者

save and retrieve values within web app

开发者 https://www.devze.com 2022-12-22 04:29 出处:网络
I have a simple web app built in asp.net webforms c# where and how would be the best way to save info from the code behind?

I have a simple web app built in asp.net webforms c#

where and how would be the best way to save info from the code behind? (and also retrieve that info)

eg all i want to save is a dateTime. and a flag set to True or False. and be ab开发者_运维技巧le to access them in the code behind.

Im not using a db for this web app.

Edit: and can't really use session variables for this purpose.

thanks


If you have to save data for an arbitrary period of time, then you need to store it in a database.


If you need to read the saved variable after a lengthy period of time, you should store it in a local file or a database.

You can create a file using a FileStream object and then write your value to the file.

To get a path where your application has sufficient rights to write a file, use Server.MapPath.

Note : If possible, and if the data you store should not be available to users, you should configure your IIS WebSite to forbid him to serve this file to clients.


Use Application variable like Application["thedate"] = date; and you can get back as date = Application["thedate"]. The date will be saved untill app pool restarts (which also happens when IIS or system restarts).

For a more longer time, save in an xml file on the disk (Use XMLReader and XMLWriter for this purpose).


If this is per user info you could use either browser cookie or viewstate.


Use the Session object:

Session["thedate"] = date;

DateTime date = (DateTime)Session["thedate"];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号