在WCF服务中使用会话时出错
本文关键字:会话 出错 WCF 服务 | 更新日期: 2023-09-27 17:50:19
我在wcf项目中使用下面的示例函数。它在内部工作得很好。当我从托管服务外部调用此函数时。它返回错误。
Object reference not set to be an instance of an object.
我发现那行HttpContext.Current。Session["UserSession"]//错误码
try
{
if (HttpContext.Current.Session["UserSession"] != null)
{
}
else
{
}
}
catch(Exception ex)
{
return ex.Message;
}
但是我想使用会话变量。请帮我解决这个问题
试试这个:
if (HttpContext.Current.Session.Contains("UserSession"))
{
if (HttpContext.Current.Session["UserSession"] != null)
{
}
}
表示会话变量为空。尝试使用缓存而不是会话,因为所有pc的