加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

会话状态信息无效,可能在ASP.Net中已损坏

发布时间:2020-12-16 07:06:00 所属栏目:asp.Net 来源:网络整理
导读:我正在使用ASP.Net 3.5和C#,开发ID:Visual Studio 2008.当我使用时 Session["FileName1"] = "text1.txt" 它工作正常,但后来我正在使用 number1=17;string FileName1="FileName1" + number1.toString(); 然后设置 Session[FileName1]="text1.txt"; 给我运行
我正在使用ASP.Net 3.5和C#,开发ID:Visual Studio 2008.当我使用时

Session["FileName1"] = "text1.txt"

它工作正常,但后来我正在使用

number1=17;
string FileName1="FileName1" + number1.toString();

然后设置

Session[FileName1]="text1.txt";

给我运行时错误

The session state information is invalid and might be corrupted
at System.Web.SessionState.SessionStateItemCollection.Deserializer(BinaryReader reader)

当我在Session变量中使用字符串时,任何人都可以解决我的问题吗?请记住,它适用于我的开发机器(意味着本地Visual Studio),但是当部署到服务器时,它会提供上述错误.

解决方法

在尝试通过Session [FileName1]语法访问它之前,请确保FileName1变量不为null …

这是一个链接到其他有同样问题的人:
http://forums.asp.net/t/1069600.aspx

这是他的答案:

在代码中,我找到了以下行:

//some code
Session.Add(sessionVarName,sessionVarValue);
//some other code

Apparently,because of some dirty data,there is a time when
sessionVarName is null.

Session.Add will not throw any exception in this case,and if your
Session Mode is “InProc”,there will be no problem. However,if your
Session Mode is “SQLServer”,during deserialization of the session
store,you will got the exception that I got. So,to filter out dirty
data,I modified the code to become:

if (sessionVarName != null)
{
  //somecode
  Session.Add(sessionVarName,sessionVarValue);
  //some other code
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读