Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC.net session gets mixed between users

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

like image 206
Nealv Avatar asked Oct 22 '25 14:10

Nealv


2 Answers

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.

like image 134
Durden81 Avatar answered Oct 25 '25 13:10

Durden81


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 ...

like image 44
Nealv Avatar answered Oct 25 '25 14:10

Nealv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!