在ASP.NET中序列化会话状态 [英] serializing session state in asp.net

查看:100
本文介绍了在ASP.NET中序列化会话状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我们的nopcommerce 1.9安装中将会话状态存储在SQL中,而不是InProc中.当我对web.config进行必要的更改时,出现此错误:

I'm trying to store session state in SQL instead of InProc in our nopcommerce 1.9 install. When I make the requisite changes to the web.config I get this error:

"/"应用程序中的服务器错误.

Server Error in '/' Application.

无法序列化会话状态.在"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.

描述:执行以下操作时发生未处理的异常当前的Web请求.请查看堆栈跟踪以获取更多信息有关错误及其在代码中起源的信息.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.Web.HttpException:无法序列化会话状态.在"StateServer"和"SQLServer"模式下,ASP.NET将序列化会话状态对象,因此无法序列化对象或MarshalByRef对象是不允许的.相同如果定制程序执行了类似的序列化,则适用限制会话状态以自定义"模式存储.

Exception Details: System.Web.HttpException: 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.

源错误:

在执行过程中生成了未处理的异常当前的Web请求.有关原产地和位置的信息可以使用下面的异常堆栈跟踪来识别异常.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

堆栈跟踪:

[SerializationException:类型中的"NopSolutions.NopCommerce.BusinessLogic.Categories.Category"Assembly'Nop.BusinessLogic,版本= 1.9.0.0,文化=中性,未将PublicKeyToken = null标记为可序列化.]
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType类型)+9449041
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type类型,StreamingContext上下文)+247
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()+160 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(TypeobjectType,ISurrogateSelector surrogateSelector,StreamingContext上下文,SerObjectInfoInit serObjectInfoInit,IFormatterConverter转换器,SerializationBinder绑定程序)+371
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfoobjectInfo,NameInfo memberNameInfo,WriteObjectInfo memberObjectInfo)+205 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfoobjectInfo,NameInfo memberNameInfo,NameInfo typeNameInfo)+651
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object图,Header [] inHeaders,__ BinaryWriter serWriter,布尔值fCheck)+444 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(StreamserializationStream,对象图,Header []标头,布尔值fCheck)+133 System.Web.Util.AltSerialization.WriteValueToStream(对象值,BinaryWriter编写器)+1762

[SerializationException: Type 'NopSolutions.NopCommerce.BusinessLogic.Categories.Category' in Assembly 'Nop.BusinessLogic, Version=1.9.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +9449041
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +247
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +160 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder) +371
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo) +205 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +651
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +444 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +133 System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1762

[HttpException(0x80004005):无法序列化会话状态.在在"StateServer"和"SQLServer"模式下,ASP.NET将序列化会话状态对象,结果是不可序列化的对象或不允许使用MarshalByRef对象.相同的限制适用如果由的自定义会话状态存储完成了类似的序列化自定义"模式.]
System.Web.Util.AltSerialization.WriteValueToStream(对象值,BinaryWriter作家)+1847
System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object值,BinaryWriter作家)+34
System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter作家)+638
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData项,流)+244
System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData项目,Int32 initialStreamSize,字节[]&buf,Int32&长度,布尔compressionEnabled)+67
System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext上下文,字符串ID,SessionStateStoreData项,对象lockId,布尔值newItem)+140
System.Web.SessionState.SessionStateModule.OnReleaseState(Object来源,EventArgs eventArgs)+807
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+148 System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值和已完成同步)+75

[HttpException (0x80004005): 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.]
System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1847
System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +34
System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +638
System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +244
System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length, Boolean compressionEnabled) +67
System.Web.SessionState.SqlSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +140
System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +807
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

版本信息:Microsoft .NET Framework版本:4.0.30319;ASP.NET版本:4.0.30319.272

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

请告诉我,我不需要序列化Nopcommerce中的每个对象来执行此操作!

Somebody PLEASE tell me I don't need to serialize every object in Nopcommerce to do this!

推荐答案

作为例外,您的类型

NopSolutions.NopCommerce.BusinessLogic.Categories.Category

不可序列化.我不知道该类型的实现,但是您可以尝试使用 [Serializable] 属性装饰该类型.

is not serializable. I dont know the implementation of that type but you can try to decorate the type with the [Serializable] attribute.

如果您不能执行此操作,则只需将对象的ID写入会话即可.

如果要将会话存储在sql服务器中,则写入会话的每个对象都必须可序列化.

If you want your session stored in sql server, every object your write into your session needs to be serializable.

这篇关于在ASP.NET中序列化会话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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