简体   繁体   English

如何从SQL Server支持的ASP.NET会话状态获取密钥列表?

[英]How to get list of keys from ASP.NET session state backed by SQL server?

I'm looking for a good way to visualize ASP.NET session state data stored in SQL server, preferably without creating a throwaway .aspx page. 我正在寻找一种可视化存储在SQL Server中的ASP.NET会话状态数据的好方法,最好不要创建一次性的.aspx页。 Is there a good way to get a list of the keys (and serialized data, if possible) directly from SQL server? 是否有直接从SQL Server获取键列表(以及序列化数据,如果可能)的好方法?

Ideally, I'd like to run some T-SQL commands directly against the database to get a list of session keys that have been stored for a given session ID. 理想情况下,我想直接对数据库运行一些T-SQL命令,以获取已为给定会话ID存储的会话密钥的列表。 It would be nice to see the serialized data for each key as well. 也很高兴看到每个键的序列化数据。

Can you elaborate slightly, is there no reference to a HttpContext available (You can use this from backend code as well FYI), which prevents you from utilizing the built in serialization and keys dictionary? 您能否详细说明一下,是否没有对HttpContext的引用(可以从后端代码以及FYI中使用它),从而阻止您使用内置的序列化和密钥字典?

EDIT, in response to your update. 编辑,以响应您的更新。 I believe the ASPState database creates and destroys temporary tables as needed, it does not have permanent tables you can query, take a look at the stored procedures and you should find one along the lines of "TempGetItem", you can either use this sproc directly, or examine its source for more insight. 我相信ASPState数据库会根据需要创建和销毁临时表,它没有可以查询的永久表,请查看存储过程,并且应该在“ TempGetItem”中找到一个,您可以直接使用此sproc ,或检查其来源以获得更多见解。

When you run asp.net application with sql server session mode, it creates two tables, dbo.ASPStateTempApplications and dbo.ASPStateTempSessions. 当您以sql server session模式运行asp.net应用程序时,它将创建两个表dbo.ASPStateTempApplications和dbo.ASPStateTempSessions。 You can find your application from first table and use it to query open sessions from second table. 您可以从第一个表中找到您的应用程序,并将其用于从第二个表中查询打开的会话。 The ASPStateTempSessions table stores two columns SessionDataShort and SessionDataLong. ASPStateTempSessions表存储两列SessionDataShort和SessionDataLong。 All session information is binary. 所有会话信息都是二进制的。 You need to know object types being stored in session if you want to deserialize them back again and view the contents. 如果要再次反序列化对象类型并查看其内容,则需要知道会话中存储的对象类型。

I have tried this recently and it works fine. 我最近已经尝试过了,效果很好。 In fact, for a complex application it is worth having some tools to view and parse session data to make sure we dont store unwanted objects and leave it in database for long - it has potential of slowing things down. 实际上,对于复杂的应用程序,值得拥有一些工具来查看和解析会话数据,以确保我们不会存储不需要的对象并将其长时间保留在数据库中-这样做可能会降低运行速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM