Are Linq to sql objects serializable for session state?(Linq to sql 对象是否可以为会话状态序列化?)
问题描述
不考虑这是个好主意还是坏主意:
Without going into whether this is a good or bad idea:
当会话处于进程外时,是否可以在 ASP.NET 会话中存储 LINQ-to-SQL 域对象?
Is it possible to store a LINQ-to-SQL domain object in the ASP.NET Session, when the session is out-of-process?
我目前收到以下错误并问了这个问题,因为我怀疑 LINQ-to-SQL 对象:
I'm currently getting the following error and asked this question because I suspect the LINQ-to-SQL objects:
无法序列化会话状态.在StateServer"和SQLServer"模式下,ASP.NET 将序列化会话状态对象,因此不允许使用不可序列化的对象或 MarshalByRef 对象.如果自定义会话状态存储在自定义"模式下完成类似的序列化,则同样的限制适用.[/编辑]
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode. [/EDIT]
例如
Session["Zoo"] = new Zoo() {
new Lion(),
new Tiger(),
new Elephant()
}
哪里:
- Zoo、Lion、Tiger、Elephant 都来自 ZooDataContext
和 web.config 文件包含
and the web.config file contains
<sessionState
mode="StateServer"
stateConnectionString="tcpip=127.0.0.1:42424"
stateNetworkTimeout="10"
sqlConnectionString="SqlStateConnectionString"
sqlCommandTimeout="30"
timeout="20"
regenerateExpiredSessionId="true"/>
推荐答案
在存储在会话或其他任何可能想要序列化的内容之前使用 datacontractserializer 序列化它们... 最近在这里讨论:
Serialize them using the datacontractserializer before storing in session or anything else that may want to serialize... Recently discussed here:
http:///social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/81c84ff4-059b-474f-9c69-b8c59027fd48
这篇关于Linq to sql 对象是否可以为会话状态序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Linq to sql 对象是否可以为会话状态序列化?
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
