【问题标题】:SqlSessionState: Unable to cast object of type System.DBNull to type System.Byte[]SqlSessionState:无法将 System.DBNull 类型的对象转换为 System.Byte [] 类型
【发布时间】:2015-06-01 15:58:30
【问题描述】:

有时我们会收到以下错误。我无法重现它。我尝试注销并导航到需要身份验证的页面,但它不会引发此异常。

到目前为止,此异常仅发生在页面加载后立即调用的 Web 服务上。 (所以页面加载发生,然后一个 onready 事件开始使用 ajax 调用加载一些数据)

我们正在使用带有 SQL Server 会话存储的 Web 表单。

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.
at System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) at System.Web.SessionState.SqlSessionStateStore.GetItemExclusive(HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) at System.Web.SessionState.SessionStateModule.GetSessionStateItem() at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我能做些什么来解决这个问题?

【问题讨论】:

  • 在调用堆栈中的某个位置,您尝试将不再在 Session 中的值转换为特定值。或者会话中存储了一个 NULL。

标签: c# asp.net webforms sql-session-state


【解决方案1】:

听起来您的会话正在超时,但您假设您正在从会话状态中检索对象。

我建议在尝试分配会话对象之前对代码添加一个空检查。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多