是LINQ到SQL对象序列化的会话状态? [英] Are Linq to sql objects serializable for session state?
问题描述
没有进入这是否是一个好的或坏主意:
是否有可能存储在ASP.NET会话一个LINQ到SQL域对象,在会话的外的过程的吗
目前,我发现了以下错误,问这个问题,因为我怀疑LINQ到SQL对象:
无法序列化会话状态。在'的StateServer'和'的SQLServer模式,ASP.NET将序列化会话状态的对象,并因此不可序列化对象或对象MarshalByRef不允许。如果类似的序列化是通过在自定义模式自定义会话状态存储做了同样的限制也适用。
[/编辑]
例如
会话[动物园] =新动物园(){
新狮()
新虎()
新象()
}
其中:
- 动物园,狮子,老虎,大象都走出了一条ZooDataContext 的
和web.config文件中包含
<的sessionState
模式=的StateServer
stateConnectionString这一=TCPIP = 127.0.0.1:42424
stateNetworkTimeout =10
sqlConnectionString =SqlStateConnectionString
sqlCommandTimeout =30
超时=20
regenerateExpiredSessionId =真/>
它们序列化使用DataContractSerializer的会话或其他任何可能要序列... <一个存放前href=\"http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/81c84ff4-059b-474f-9c69-b8c59027fd48\"相对=nofollow>最近这里讨论的:
<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/81c84ff4-059b-474f-9c69-b8c59027fd48\" rel=\"nofollow\">http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/81c84ff4-059b-474f-9c69-b8c59027fd48
Without going into whether this is a good or bad idea:
Is it possible to store a LINQ-to-SQL domain object in the ASP.NET Session, when the session is out-of-process?
[EDIT] I'm currently getting the following error and asked this question because I suspect the LINQ-to-SQL objects:
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]
e.g.
Session["Zoo"] = new Zoo() {
new Lion(),
new Tiger(),
new Elephant()
}
where:
- Zoo, Lion, Tiger, Elephant all come out of a ZooDataContext
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"/>
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到SQL对象序列化的会话状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!