Web サービスのセッションに値を保存しようとしていますが、エラーが発生します: object reference not set to an instance of an object
.
Session["ProcessStartTime"] = strDate;
Web サービスのセッションに値を保存しようとしていますが、エラーが発生します: object reference not set to an instance of an object
.
Session["ProcessStartTime"] = strDate;
strDate
がnullでないことを確認してくださいSession["ProcessStartTime"] = strDate;
before宣言メソッドを使用してセッションを有効にしたことを確認してくださいここにサンプルがあります
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
}
}
Web メソッドに追加(EnableSession = True)
します。
[WebMethod (EnableSession = true)]
またはWeb サービスでセッション状態を使用する方法に関するこの素晴らしい記事を読む