如何在.net中的会话中节省价值

本文关键字:节省 会话 net | 更新日期: 2023-09-27 18:00:11

我试图在webservice的会话中保存值,但它给了我错误:object reference not set to an instance of an object

Session["ProcessStartTime"] = strDate;

如何在.net中的会话中节省价值

(EnableSession = True)添加到WebMethod

[WebMethod (EnableSession = true)]

或者阅读这篇关于如何在web服务中使用会话状态的好文章

  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
         }
    }