会话存储数据,并在每次使用该应用程序时显示相同的值. [英] session store data and show the same value for each time i use the application.

查看:76
本文介绍了会话存储数据,并在每次使用该应用程序时显示相同的值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经开发了一个Web应用程序,当用户返回时,所有条目都已过期.我希望当用户返回时,可以看到他们在最后一页上输入的所有条目.

例如,如果用户输入如下内容:

第一页:用户名,User_ID
第二页:Q1
第三页:第二季度
第四页:第三季度
第五页:第四季度
第六页:完整

在数据库中,答案将根据用户ID保存.查询就像:


更新Q1 ="value",其中User_ID = @User_ID
更新Q2 ="value",其中User_ID = @User_ID
更新Q3 ="value",其中User_ID = @User_ID



因此,如果用户想再次编辑Q2,那么他可以返回并编辑最后一个答案,但是在我的情况下,当用户返回时,他的最后一个答案将保存在数据库中,而不是保存在页面上.因此,我希望他在完成之前可以查看或编辑以前的答案,然后就可以对其进行编辑.

为此,我使用了此解决方案........

Response.Redirect("Next_Page.aspx");
获取控件的值后的某个位置.在此行之前,添加您要存储的控制值的代码
如下所示-Session ["UserName"] = txtUserName.Text;
会话["UserID"] =用户ID;
等等.然后在上一页加载中检查这些值是否在会话中,
然后将值填充到如下所示的适当控件中...
内部Page_Load()---- if(Session ["UserName"]!= NULL){txtUserName.Text = Session ["UserName"].ToString(); }
if(Session ["UserID"]!= NULL){txtUserID.Text = Session ["UserID"].ToString(); }等等.....

为了结束会话,我在应用程序的最后一页和终止页面上使用了session.abendon属性.

它可以工作,但是会保存我每次使用此应用程序时输入的值,以及如果有一个以上的用户同时使用此应用程序,该操作将保存,因为它始终显示会话中存储的相同值?


任何帮助表示赞赏.

谢谢.

Hi All,

I have developed a web application and the when user goes back all the entries are expired. I want that when user goes back, all the entries they entered on the last page are viewable.

For example if a user entered like :

first page : User Name,User_ID
Second Page : Q1
Third Page : Q2
Fourth Page : Q3
Fifth Page : Q4
Sixth Page : Complete

In database answer will save according to User ID. Query is like :


Update Q1= "value" where User_ID = @User_ID
Update Q2= "value" where User_ID = @User_ID
Update Q3= "value" where User_ID = @User_ID



So if user want to edit Q2 again then he can go back and edit the last answer but in my case when user go back then his last answer will save in database but not on the page. So i want whenever he want to review or edit the previous answers before complete he can go and edit it.

for this i have used this solution...........

Response.Redirect("Next_Page.aspx");
somewhere after getting the values of the controls. Just before this line add the codes for the conrol values u want to store
like below - Session["UserName"] = txtUserName.Text;
Session["UserID"] = UserID;
and so on..... And then in previous page load check whether these value are in session or not,
then fill values to appropriate controls as below...
Inside Page_Load() ---- if(Session["UserName"] != NULL) { txtUserName.Text = Session["UserName"].ToString(); }
if(Session["UserID"] != NULL) { txtUserID.Text = Session["UserID"].ToString(); } and so on.....

For ending the session i have used session.abendon property on the last page and on the terminate page of the application.

It work''s but it saves the value i have entered for every time i use this application and what if more then one user use this application at the same time, because it show''s all the time same value stored in the session ?


Any help is appreciated.

Thanks.

推荐答案

会话中存储的值就是这样-通过该连接,该用户特定于该用户,直到他离开或会话超时为止.如果他在会话超时时间内从相同的IP地址返回到同一页面,并且IIS尚未重新启动,则有可能(但不能保证)他将检索以前的值.会话值绝不会在不同用户之间共享.

如果您希望保存从连接到连接的值,则将它们存储为cookie-它们驻留在客户端上,因此特定于他,并且将保留到您想要的时间.
如果您希望会话绝对重新启动,请在加载第一页时明确清除会话变量,或将其设置为合理的默认值.
Values stored in the Session are just that - they are specific to that user, via that connection, until he goes away or the session times out. If he comes back to the same page from the same IP address within the session timeout period and IIS has not been restarted, it is possible (but not guaranteed) that he will retrieve the previous values. At no time will Session values be shared between different users.

If you want the values saved from connection to connection, then store them as cookies - these reside on the client, so are specific to him, and will be retained for as long as you like.
If you want the session to definitely restart, then clear the session variables explicitly when you load the first page, or set them to sensible defaults.


这篇关于会话存储数据,并在每次使用该应用程序时显示相同的值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆