如何在.net中的会话中节省价值
本文关键字:节省 会话 net | 更新日期: 2023-09-27 18:00:11
我试图在webservice的会话中保存值,但它给了我错误:object reference not set to an instance of an object
。
Session["ProcessStartTime"] = strDate;
将(EnableSession = True)
添加到WebMethod
[WebMethod (EnableSession = true)]
或者阅读这篇关于如何在web服务中使用会话状态的好文章
- 确保您的
strDate
不为空 - 在声明方法之前检查是否已使用
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
}
}