会话 ASP.NET
asp.net/c# 中的会话问题
我有多个 asp.net 页面和一个类对象。 例如 类 User 对象包含
public string Name { set; get; }
public string Address { set; get; }
etc.....
pg1.aspx:当单击按钮时,数据存储在会话中并重定向到 pg2.aspx,
例如pg1.aspx
User u = new User();
u.Name = TextBox1.Text;
Session.Add("USERINFO", u);
Response.Redirect("pg2.aspx");
例如pg2.aspx //读取数据..
User u = ((User)Session["USERINFO"]);
Response.Write(u.Name + "<br/>");
..等..(我有5页,数据在会话中从一页传递到另一页)一旦用户到达它存储在数据库中的最后一页,否则我不希望在数据库中存储不完整的数据。
一切正常,除非我使用多个选项卡运行同一个网络应用程序,数据会相互覆盖...如果我使用单独的浏览器,但不使用选项卡,则一切正常...
我怎样才能避免用户在中输入数据tab1 转到第 3 页,如果用户打开 tab2 并且继续不超过 tab1 中输入的数据...
我希望这是有道理的...我正在努力完成的任务...谢谢。
Session question in asp.net/c#
I have multiple asp.net pages and a class object.
e.g.
Class User object contains
public string Name { set; get; }
public string Address { set; get; }
etc.....
pg1.aspx: when button is clicked, the data is stored in the session and redirects to pg2.aspx
e.g. pg1.aspx
User u = new User();
u.Name = TextBox1.Text;
Session.Add("USERINFO", u);
Response.Redirect("pg2.aspx");
e.g. pg2.aspx //reading the data..
User u = ((User)Session["USERINFO"]);
Response.Write(u.Name + "<br/>");
..etc.. ( I have 5 pages and the data is passed around from page to page in a session) once the user reaches the last page it stores in the database otherwise I dont want to store incomplete data in the database.
It all works fine except if I use multiple tabs to run same web app, the data overwrites eachother... It works fine if I use separate browsers, but not with tabs...
How can I avoid a user to enter the data in tab1 get to page 3 and if the user opens tab2 and continues not to over the data was entered in tab1....
I hope it makes sense... what I am trying to accomplish... Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是一个重复的问题,所以我将简单地将您重定向到一些可以解决您的问题的答案。
不幸的是,接受的答案不起作用,因为它为每个页面维护一个“唯一”会话标识符,而不是您的 5 个页面组。
您的浏览器版本以及在其中启动新选项卡和窗口的不同方法决定了会话是否在多个选项卡和窗口之间共享。可以通过
This is probably a duplicate question, so I'll simply redirect you to some answers that would solve your problem.
Unfortunately, the accepted answer won't work since it maintains a "unique" session identifier for each page, not your group of 5 pages.
Your browser version and the different methods of launching new tabs and windows in it determines whether sessions are shared across multiple tabs and windows. Controlling it could be done with
解决当前实现的最简单方法可能是检查您是否拥有您期望从该页面获得的信息,如果不满足条件,则需要输入数据,或者根据具体情况适当重定向您所处流程的阶段(基于可用的数据)。
因此,除了添加到会话之外,您还可以获得:
并且您可以从那里建立您的条件
The simplest way to work around your current implementation would likely be to check whether or not you have the information you would expect from that page, and if the conditions aren't met then require the data to be input, or redirect appropriately depending on which stage in the process you are (based on the data that is available).
So, as well as adding to the session, you can get:
And you can build upon your conditions from there