5

如果其中没有存储任何值,我确定 Session id 会不断变化。

在此处输入图像描述

但似乎 2010 年有一个例外: 这是演示视频

新页面(空项目):

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

奇怪但在回发/刷新/ ctrl+f5 之后:我得到了相同的数字......但它应该是那样......(因为我没有存储任何东西)

在此处输入图像描述

我错过了什么?

ps Session.Count = 0.....

编辑

我只是在vs2005中运行相同的代码,每次都有一个新的会话 ID !!!

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

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.

于 2012-04-18T09:50:11.177 回答