5

Im certain that Session id keeps changing if no value is stored in it.

enter image description here

but seems that 2010 have an exception : here is the demo vid

new page ( empty project) :

   protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Session.SessionID);
    }

strange but after postback / refresh / ctrl+f5 : i get the same number...but it should'nt be like that....(since i didnt store nothing)

enter image description here

what am i missing?

p.s. Session.Count =0.....

edit

ive just run the same code in vs2005 and a new session id is each time !!!!

enter image description here

enter image description here

enter image description here

Royi Namir
  • 144,742
  • 138
  • 468
  • 792

1 Answers1

2

It should be like that.

Session is a special ASP.NET runtime object that exists for all requests/responses during the determined time. It's by design that it remains the same, doesn't matter it's page load or post back.

The session terminates then it reach it's timeout period. You might control what exact timeout you want to keep you session alive:

Session timeout in ASP.NET

You also able to control where the session is persisted between the request.

http://msdn.microsoft.com/en-us/library/z1hkazw7.aspx

In Memory state management is simplies one, it just keeps Session object in RAM. So in case of app-pool is recycled all data is gone. More production-ready scenarios include SQL state management.

EDIT: I just assume, that then you running on VS2005, you run on old version of ASP.NET Web Development server (Cassini) that indeed my work in the way to have Session with each new request, if nothing is stored in Session yet.

Community
  • 1
  • 1
Alexander Beletsky
  • 19,453
  • 9
  • 63
  • 86
  • If memory serves, its preserved through cookies? Or am I mistaken and its server side? – Venatu Apr 18 '12 at 09:50
  • i think you are wrong. Ive just run it in vs2005 and i get a new id each time . – Royi Namir Apr 18 '12 at 09:51
  • 1
    @RoyiNamir, go ahead and open asp.net book.. read about session management. – Alexander Beletsky Apr 18 '12 at 09:54
  • 1
    You only get a new ID each time you run the app, not when you refresh the page. If you get a new ID each time you refresh the page then there's something wrong. – Reinstate Monica Cellio Apr 18 '12 at 09:54
  • @Archer. it's not completely true.. in case of SQL state management, for instance.. you might persits the same session even if app re-lauched (iis restarted) – Alexander Beletsky Apr 18 '12 at 09:56
  • 1
    @alexanderb That goes against what a session object actually is. If IIS is restarted then the session cannot still exist - not even the application still exists. – Reinstate Monica Cellio Apr 18 '12 at 09:57
  • @alexanderb i dont like your attitude... believe me - I know session management. lets go back to the question. in vs2005 - each f5 it gives me a new sessionID and in vs2010 it keeps the same... so? – Royi Namir Apr 18 '12 at 10:00
  • @Archer from msdn : `As a result, a new session ID is generated for each page request until the session object is accessed.` http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspx I think im not the one who should open asp.net book....:) – Royi Namir Apr 18 '12 at 10:02
  • @Namir: that paragraph starts with `When using cookie-based session state...` See first answer of http://stackoverflow.com/questions/2874078/asp-net-session-sessionid-changes-between-requests – mshsayem Apr 18 '12 at 10:03
  • 2
    @mshsayem - and we _are_ using cookies, since the URL in the screenshot does not contain a session ID. – Jonas Høgh Apr 18 '12 at 10:05
  • @Archer i do use cookie based session the name is AspnetSession_id or something like that... – Royi Namir Apr 18 '12 at 10:07
  • @alexanderb i read your edit... and still how does it settle with the link in msdn... "for each request....a new session id...(if nothing store....)"? – Royi Namir Apr 18 '12 at 10:23
  • @Archer https://skydrive.live.com/redir.aspx?cid=fe3c089563fd353c&resid=FE3C089563FD353C!539&parid=FE3C089563FD353C!174&authkey=!AGge923yUmaDFgk – Royi Namir Apr 18 '12 at 10:26
  • @alexanderb https://skydrive.live.com/redir.aspx?cid=fe3c089563fd353c&resid=FE3C089563FD353C!539&parid=FE3C089563FD353C!174&authkey=!AGge923yUmaDFgk – Royi Namir Apr 18 '12 at 10:28
  • @JonasH https://skydrive.live.com/redir.aspx?cid=fe3c089563fd353c&resid=FE3C089563FD353C!539&parid=FE3C089563FD353C!174&authkey=!AGge923yUmaDFgk – Royi Namir Apr 18 '12 at 10:28
  • @Royi Very interesting. I noticed that your VS2010 project is not empty. Could it be some other component somewhere else in the code that is messing with the session somehow? – Jonas Høgh Apr 18 '12 at 10:32
  • @JonasH it has some other pages but the started page is default.aspx which has no lines at all !( except code as youve seen) ...also : global.asax is empty...also - no other dll or cs code access the session....... it is strange....indeed... – Royi Namir Apr 18 '12 at 10:34
  • @JonasH http://i.stack.imgur.com/XAcP8.jpg ( ive made what alexander told me and open asp.net book hhhhh) [oreilly pro asp.net] – Royi Namir Apr 20 '12 at 07:37