我正在尝试将用户控件存储在回发之间的会话状态中,使用 SQL 作为状态服务器。
我得到类不可序列化错误:
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.
堆栈跟踪
SerializationException: Type 'ASP.bookingcontrols_controls_ucDates_ascx' in Assembly 'App_Web_eckjngpu, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]
现在,将 usercontorl 类标记为可序列化,我仍然收到此错误。从研究中我已经确定,到目前为止,用户控件不能被序列化。美好的。
解决此问题的一般建议想法似乎是将控制(数据)与控制(接口/前端)分离,并在另一侧重建它。
现在,在我尝试对我的代码进行一些有影响的更改之前,我的问题如下:
派生自 usercontrol 类但未page.loadcontrol("control.ascx")
通过 如果是这样,我假设我不能从控件类继承来获取属性,因为它最终会继承不可序列化的用户控件类?
例子:
不使用:
Dim myDatesControl As New UserControl
myDatesControl = Page.LoadControl("~/bookingControls/ucDates.ascx")
With CType(myDatesControl, controls_ucDates)
.checkInDate = Session("nowcheckin")
.checkOutDate = Session("nowcheckout")
.Nights = "xxx"
.guid = currentBookingFilter.guid
.ExtraInfo = currentBookingFilter
End With
以下工作是否可以作为可序列化为进程外会话状态的对象。
Dim myDatesControl As New controls_ucDates
With CType(myDatesControl, controls_ucDates)
.checkInDate = Session("nowcheckin")
.checkOutDate = Session("nowcheckout")
.Nights = "xxx"
.guid = currentBookingFilter.guid
.ExtraInfo = currentBookingFilter
End With
在第二个块中,myDatesControl
可以序列化吗?