MVC.net 会话在用户之间混合

发布于 2024-10-10 15:29:15 字数 1190 浏览 4 评论 0原文

我将用户对象存储在会话中,将它们拉出到控制器中,有时向其中写入一些数据。但是当用户同时发帖时,会话会由于某种原因而混合在一起。

有谁知道这怎么可能?

典型的帖子:

  [HttpPost]
    public ActionResult Index(QuestionModel model, FormCollection collection)
    {
        var person = ((Person)Session["Person"]);
        if (!ModelState.IsValid)
        {
            ModelState.Clear();
            ModelState.AddModelError("", Global.Global.error);
            return View(new QuestionModel(person.page, (CultureInfo)Session["culture"]));
        }
        person.page = model.Page;
        while (person.Answers.Count > model.Page - 1)
        {
            person.Answers.RemoveAt(person.Answers.Count - 1);
        }
        var answer = new Answer() { answer = model.ChosenAnswer, Question = "Q" + person.page };
        person.Answers.Add(answer);
        if (!CheckForNextPage(person.page)) { person.hasFinishedQuestions = true; return RedirectToRoute("Result"); }
        person.page++;
        return View(new QuestionModel(person.page, (CultureInfo)Session["culture"]));
    }

我在每个页面上回显会话ID,当几个用户使用该网站时,他们会得到彼此的会话+会话ID...

@更新:3位经验丰富的开发人员已经寻找问题2天了,仍然没有解决方案。已经删除了大约 95% 的代码,仍然是同样的问题。服务器发回另一个会话的响应

I am storing user objects in session, pulling them out in the controllers, and sometimes write some data into them. but when to users post at the same time, the sessions get mixed fro some reason.

Does anyone have any idea how that is possible ?

typical post:

  [HttpPost]
    public ActionResult Index(QuestionModel model, FormCollection collection)
    {
        var person = ((Person)Session["Person"]);
        if (!ModelState.IsValid)
        {
            ModelState.Clear();
            ModelState.AddModelError("", Global.Global.error);
            return View(new QuestionModel(person.page, (CultureInfo)Session["culture"]));
        }
        person.page = model.Page;
        while (person.Answers.Count > model.Page - 1)
        {
            person.Answers.RemoveAt(person.Answers.Count - 1);
        }
        var answer = new Answer() { answer = model.ChosenAnswer, Question = "Q" + person.page };
        person.Answers.Add(answer);
        if (!CheckForNextPage(person.page)) { person.hasFinishedQuestions = true; return RedirectToRoute("Result"); }
        person.page++;
        return View(new QuestionModel(person.page, (CultureInfo)Session["culture"]));
    }

I echo the session id on every page, and when a couple of users are using the website they get each others session + sessionid ...

@update: 3 experienced developers have been looking for the problem for 2 days, still no solution. already removed about 95% off the code, still same issue. server posts back responses from another session

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人疚 2024-10-17 15:29:16

我们“解决”了它。我们实际上并没有解决这个问题,但是我们将所有源代码复制到一个新项目中,重新编译,然后一切正常。直到今天,我们仍然不知道为什么会发生这个错误,也不知道这个错误是如何发生的......

We "solved" it. We didn't actually solve it, but we copied all the sources to a new project, recompiled, and everything worked. Untill this day, we still don't know why, and how that error happened ...

已下线请稍等 2024-10-17 15:29:15

这是不可能的。
所以这是我的猜测:
您错误地测试了这一点,您使用的是同一浏览器中的不同选项卡。
有些人不知道这不会创建不同的会话。

尝试在 2 个不同的浏览器(即 firefox 和 chrome)上进行测试,因为它们不会共享会话(因为会话 ID 通常存储在 cookie 中)。

如果是这种情况,请报告。

This is not possible.
So this is my guess:
You are testing this wrongly, you are using different tabs from the same browser.
Some people don't know that this doesn't create a different session.

Try testing this on 2 different browsers (i.e. firefox and chrome) as they will not share the session (as the session id is normally stored in a cookie).

Please report back if this was the case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文