User Sessions

Hi, new to creating a web site. I bought “Build your own asp.new 2.0 website using c# & Vb.” and I’m using Visual Studio 2005.

The book seems good so far but I’m now having a problem. I think I need to use “User Sessions” but I can’t get them to work. The code works fine using Applications but when I change to Sessions, when I go into a page the value is always null.

I did find one reference on the web that suggests I need “using System.Web.SessionState.HttpSessionState” defined but there doesn’t seem to be anything after “System.Web.SessionState”.

I’ve tried using the counters example in the book but with Session I only ever get 1 coming up which is the reset value when the Session[“xxx”] is null.

Anyone have any ideas.

Thanks

That’s why I think it’s a setup problem. i don’t know if not finding
“using System.Web.SessionState.HttpSessionState” is a clue.

Could it be an IIS problem.

Hmm, a bit strange, cos the code looks perfect

It’s just the example in the book. This code below doesn’t work (it always gets into the ==null and sets the variable to 1). I change Session to Application and it works correctly. This makes me think I haven’t set up something somewhere.

protected void Page_Load(object sender, EventArgs e)
{
if (Session[“PageCounter”]!=null &&
(int)Session[“PageCounter”] >= 10)
{
Session.Remove(“PageCounter”);
}
if (Session[“PageCounter”] == null)
{
Session[“PageCounter”] = 1;
}
else
{
Session[“PageCounter”] = (int)Session[“PageCounter”] + 1;
}
Label1.Text = Convert.ToString(Session[“PageCounter”]);
}

It would help us if you show us your code, as you might be doing something wrong that the people in the forum can pickup.