C# 在WCF服务中使用会话时出错
我正在wcf项目中使用下面的示例函数。内部运作良好。当我从托管服务外部调用此函数时。它返回错误C# 在WCF服务中使用会话时出错,c#,asp.net,web-services,wcf,c#-4.0,C#,Asp.net,Web Services,Wcf,C# 4.0,我正在wcf项目中使用下面的示例函数。内部运作良好。当我从托管服务外部调用此函数时。它返回错误 Object reference not set to be an instance of an object. 我发现行HttpContext.Current.Session[“UserSession”]//错误代码 try { if (HttpContext.Current.Session["UserSession"] != null) { } else
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;
}
但是我想使用session变量。请帮我解决这个问题。试试这个:
if (HttpContext.Current.Session.Contains("UserSession"))
{
if (HttpContext.Current.Session["UserSession"] != null)
{
}
}
这意味着您的会话变量为空。
尝试使用缓存而不是会话,因为所有pc的会话值都不同?难道不是
吗
?请阅读支票,让我们看看您的服务和网站。config@KamranShahid非常感谢你。链接工作正常。