I am doing a jquery $.post(‘/Home/jQueryRateForumItem’, but when I get to my controller the session id is always different on each post.
I have tried;
string g = HttpContext.Session.SessionID;
string session = base.Session.SessionID;
I’m pretty sure The session id shouldn’t change but can’t for the life of me think how to fix this.
EDIT
It’s happening when I refresh the Index page as weel so not just on ajax postbacks. I am using cassini and not IIS though this is the first time I’ve had issues
I can’t see anything wrong with your code and I couldn’t reproduce the behavior you are describing. By default sessions are tracked by cookies so make sure that you’ve enabled cookies on your browser or it might create a new session on each request.
Also make sure you store a value into the session or the session cookie won’t be created. Let’s take for example the following controller:
First navigate to the
Homeaction, then go toAboutand when you come back toHomethe session id changes. That’s normal as nothing was stored into the session. If you simply set some valueSession["foo"] = "bar";it will work as the session cookie will be set by the server.