会话如何在asp.net中工作? [英] How the session work in asp.net?

查看:65
本文介绍了会话如何在asp.net中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人建议我该会话在asp.net中的实际工作方式是什么? 我在会议的一部分中感到困惑,并想简短地了解一下,所以请指导我

Please any one suggest me how the session is actually work in asp.net? I am confuse in part of session and want to briefly knowledge of it so please guide me

推荐答案

ASP.NET使用cookie来跟踪用户.当您第一次尝试向会话中写入内容时,会将cookie发送给客户端,例如ASP.NET_SessionId.该cookie由客户端根据后续请求发送.借助此cookie,服务器可以识别客户端并写入/读取关联的会话数据.重要的是要注意,该cookie不是持久性的(浏览器无法重启),并且会与 HttpOnly 标志意味着客户端脚本无法访问它.

ASP.NET uses a cookie to track users. When you try to write something to the session for the first time a cookie is sent to the client, something like ASP.NET_SessionId. This cookie is sent by the client on subsequent requests. Thanks to this cookie the server is able to identify the client and write/read the associated session data. It is important to note that this cookie is not persistent (wouldn't survive browser restarts) and is emitted with the HttpOnly flag meaning that client scripts cannot access it.

除了cookie,您还可以将ASP.NET配置为使用隐藏字段,或将会话ID附加到每个请求的查询字符串中.

In addition to cookies you could also configure ASP.NET to use hidden fields or append the session id to the query string on each request.

因此,会话背后的基本思想是,实际数据存储在服务器上的某个位置,并且客户端在每个请求上发送一些ID,以便服务器可以知道在何处查找其数据.

So the base idea behind session is that the actual data is stored somewhere on the server and the client sends some ID on each request so that the server can know where to find its data.

默认情况下,可以在3个地方存储实际的会话数据:

By default there are 3 places where the actual session data can be stored:

  • 进行中:会话存储在应用程序的内存中(最快,但是如果服务器场中有多个服务器,则无法使用
  • )
  • 过程外:将数据存储到安装了State Service的单独服务器中(数据存储在单独计算机的内存中,这意味着多个Web服务器可以在一个Web场中工作)
  • SqlServer:数据存储在SQL Server中(这是最慢但最可靠的方法,因为会话数据存储在SQL Server数据库中,并且如果Session服务器崩溃则可以提供服务,而Out-Of-Proc则不会这样)
  • 自定义实现:由于ASP.NET的可扩展性,您可以编写自己的会话提供程序并将数据存储在任意位置.

这是一篇有关MSDN的好文章,探讨了 ASP.NET会话状态.

Here's a good article on MSDN which explores the ASP.NET Session State.

这篇关于会话如何在asp.net中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆