0

在 ASP.NET 中,会话是针对浏览器的。但是如何为选项卡创建会话?

4

2 回答 2

2

使用以下内容:

<configuration>
  <system.web>
    <sessionState cookieless="true"
      regenerateExpiredSessionId="true" />
  </system.web>
</configuration>

以及来自 MSDN的引用

ASP.NET 通过自动将唯一的会话 ID 插入页面的 URL 来维护无 cookie 会话状态。例如,以下 URL 已被 ASP.NET 修改为包含唯一会话 ID lit3py55t21z5v55vlm25s55:

http://www.example.com/(S(lit3py55t21z5v55vlm25s55))/orderform.aspx

当 ASP.NET 向浏览器发送页面时,它会通过在链接中嵌入会话 ID 值来修改页面中使用应用程序相对路径的任何链接。(带有绝对路径的链接不会被修改。)只要用户单击以这种方式修改的链接,会话状态就会保持。但是,如果客户端重写应用程序提供的 URL,ASP.NET 可能无法解析会话 ID 并将请求与现有会话相关联。在这种情况下,会为该请求启动一个新会话。

因此,为新选项卡打开新会话所需的只是打开一个没有会话标识符的 url。
编辑:
正如其他用户所提到的,你应该照顾好这个“功夫”。如果您在会话中存储用户敏感信息 - 请保护您的身份验证 cookie

EDIT2: And be aware that when you'll use session key in url the users can copy it and send to some friends. And this user and his friends will share the single session (this will be a great feature! :)). To avoid this you can do the following:
1. Add somehow association to user (user's profile, store in database) in onSessionStart method and check it on BeginRequest.
2. Check referrer and create new session (redirect to sessionless url) when referrer is empty or it not equals to the current domain (but be aware that referrer can be manually set)
3. Rewrite generation of session ID and associate it with the username and ip/mac (xor or something like this). And verify this on the stage when session is picked up.
4. Something else to make this session key valid only to current user.

于 2009-06-05T10:41:04.010 回答
1

会话 cookie 保存在该浏览器实例可访问的易失性存储中。您将需要一个支持您所追求的概念的浏览器,据我所知,不存在这样的浏览器。

在 ASP.NET 中,您可以在不使用会话 cookie 的情况下维护会话,它真的很丑,我不推荐它,但它可能是您实现目标的一种方式。

于 2009-06-05T10:30:35.263 回答