2013-02-20 54 views
0

我试图在web服务中保存会话中的值,但它给了我错误:object reference not set to an instance of an object如何在.net中保存会话中的值

Session["ProcessStartTime"] = strDate; 
+0

确保会话状态为您的web服务启用。 – 2013-02-20 10:51:25

+0

您需要将会话支持添加到Web服务。你使用什么Web服务技术? – Lloyd 2013-02-20 10:51:35

+0

你在使用什么样的文件Session对象? – algreat 2013-02-20 10:56:44

回答

0
  1. 这个好文章,请确保您的strDate不为空
  2. 检查你声明的方法之前,使用Session["ProcessStartTime"] = strDate;启用会议

这里是一个样本

public class mytest: System.Web.Services.WebService 
    { 
     [WebMethod (EnableSession = true)] 
     public string HelloWorld() 
     { 
      //your logic here 
      if(strDate!=null) 
        Session["ProcessStartTime"] = strDate; 
      else 
       // handle if ur strDate is null 
     } 
    }