Himberjack
Himberjack

Reputation: 5792

Sharing Session between 2 ASP.NET Requests

I am trying to figure out an issue im having: I have multiple calls to the same function simultaneously.

    private const string aaaa= "aaaaa";
    protected bool test()
    {

        if (Session[aaaa] != null && (bool)Session[aaaa])
            return false;

            Session[aaaa] = true;
            return true;
    }

Thing is - all my requests ignoring the Session[aaaa] != null && (bool)Session[aaaa] and keep on as if no such session variable was defined!

How can It be? When is the session being updated?

Upvotes: 1

Views: 231

Answers (1)

Patrick
Patrick

Reputation: 7712

you need to set the session variable before you can use it....

session.add("aaaa", "some string");

then later you can come back and say...

string result = session["aaaa"].tostring();

Hopefuly this will help

    Protected void Page_Load(object sender, EventArgs e)
    {
        Session.Add("BoolTest", "False");
    }

    Protected Bool test()
    {
          return (bool)Session["BoolTest"].tostring();
    }

Result; test = false

some point later in the page you would say...

Session["BoolTest"] = True;

Result; test = true

Upvotes: 1

Related Questions