尝试从会话中存储的数组列表中检索值时出现问题

问题描述

| 请帮我。这是我的代码
ArrayList arrValues = new ArrayList();
arrValues = (ArrayList)Session[\"ArrValues\"];

string CustName,Addr1,Addr2,City,State,Country,Pin,Email,Order,CustToken;
string SName,SAddr1,SAddr2,SCity,SState,SPin,SCountry;         

CustName = arrValues[1].ToString().Trim();
试图从存储在会话中的数组列表中获取值“ 1”时,它正在处理“ NullReference excption”。以下是观看视频的链接 http://www.talash.com/testingvideo/2011-03-18_0958_Payment_Gateway_Problem.swf     

解决方法

问题是您的会话变量不存在。 arrValues为空。您需要研究为什么丢失会话变量。 您是否要从页面或模块中获取此值? 如果使用HttpModule,则会话并非始终可用,并且会话对象可能为null。     ,由于之前您的会话变量未设置为任何值,因此这就是您收到错误的原因。请通过将其插入这样的代码来使此代码安全。
if(Session[Arrvalues\"]!=null)
{

    //your block of code//

 }
else
 {
    Response.Redirect(\"to_the_page_where_this_session_variable_is_set.aspx\");


  }
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...