views:

1213

answers:

5

I am trying to keep track of something and using the SessionID as they key to that object

However the SessionID every 2-3 reqiests changes shouldn't it remain the same?

HttpContext.Session.SessionID

Is the code I am using.

+2  A: 

I would look into using TempData to keep track of something.

MrJavaGuy
Actually all I had to do was assign a session variable a value and that made it stick..
dswatik
A: 

Try with adding machine key into your web.config:
Online key generator: http://aspnetresources.com/tools/keycreator.aspx It seems that server resets machine key for client and generates new one with new session id, every few minutes, which is much lower than it should. Don't know if that's bug or feature:)
Also, you can increase your session state timeout, which is i think 20min by default.

Hrvoje
+5  A: 

I've seen that happen even without MVC. If I remember correctly, ASP.NET keeps assigning new session ids until you place something into the Session variable.

it looses session even if you put something into it. Machine key inside web.config is the only thing that addresses that issue
Hrvoje
Only if there was a web farm involved. And if you read the OP's comment in one of the answers, you'll find that adding an item to the session variable did fix the problem.
My hosting provider doesn't have web farm, and adding stuff to session don't fix it. I still loose it after few minutes - even if i have lot of stuff in session (loged user, his shop basket,...) I tried with 2 hosting providers
Hrvoje
This is rather strange behavior but it is true, assigning any data to Session collection solves this problem.
zidane
A: 

I am working on a .NET MVC cart application and I added

Session["myVar"] = "1234";

to the Page_Load method found in the Default.aspx.cs code. I also added

<%= this.Session.SessionID %>

to the Site.Master footer. I then rebuilt my app and browsed the various pages of my app and the footer displays the same session id for all pages as expected!

robnardo
A: 

If you look the seession ID cookie is not even sent to the browser unless it's used on the server.

So when a page roundtrips there is no current session ID cookie, so a new session ID is created, hence it is random.

This is logical, why bother tying up the app to a session if the session is not in use?

ScottEg