不知道如何在sql会话状态中存储会话id
我是 ASP.NET 新手。我正在创建一个网站,我必须在其中为登录该网站的每个用户创建会话。现在我无法想象如何在数据库中存储会话。
我读了几本书,了解了如何配置会话状态。但我仍然在我开始的地方。我无法获取应该在哪里保存会话 ID。 我正在使用 sql server 会话状态。我已经创建了数据库 aspnetdb 及其上的所有表。但我不知道如何使用它们。如何将我的会话 ID 保存到数据库中。 我完全困惑如何解释我的问题。
I am new to ASP.NET. I am creating a website in which i have to create session for every user who gets login into the site. Now I am not been able to picturize how to store session in my database.
I read few books for the same and got how to configure Session state. But i m still at the same place where i started. I am not able to get where should i save session id.
I m using sql server session state. I have created database aspnetdb and all tables r over their. But i dont know how to use them. How to save my session id into database.
I m totally confused how to explain my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅如何:配置 SQL Server 以存储 ASP.NET 会话状态
基本上,您必须配置它在 web.config 中:
See HOW TO: Configure SQL Server to Store ASP.NET Session State
Basically, you have to configure it in web.config:
您不需要将会话 ID 存储在数据库中——该部分由运行时为您完成,假设您在 SQLServer 模式下使用会话。
会话提供程序将在每个请求开始时从数据库读取会话数据,并在每个请求结束时写入。它通过设置包含会话 ID 的 cookie,然后使用 cookie 的值作为数据库查找的键来查找其余会话数据来实现此目的。
您始终可以从 Session.SessionID 属性访问会话 ID,但您应该很少需要这样做。
直到您第一次在 Session 对象中保存某些内容时,Session ID cookie 才会发送到客户端(会话数据也不会保存在数据库中)。您可以使用 Fiddler 等 Web 调试器轻松查看这一点。
FWIW,通常不应使用会话状态来处理登录。例如,标准 ASP.NET 会员资格提供程序使用基于 cookie 的并行系统。
You don't need to store the session ID in the database -- that part is done for you by the runtime, assuming that you're using sessions in SQLServer mode.
The Session provider will read the session data from the DB at the beginning of each request, and write it at the end of each request. It does this by setting a cookie that contains the session ID, and then using the value of the cookie as the key for the DB lookup it does to find the rest of the session data.
You can always access the session ID from the Session.SessionID property, but you should rarely need to do so.
The Session ID cookie is not sent to the client (nor is the session data saved in the DB) until the first time you save something in the Session object. You can see this easily with a web debugger such as Fiddler.
FWIW, normally logins should not be handled using session state. The standard ASP.NET Membership provider, for example, uses a parallel system that's based on cookies.