Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WCF服务中使用会话时出错_C#_Asp.net_Web Services_Wcf_C# 4.0 - Fatal编程技术网

C# 在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

我正在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;
}
但是我想使用session变量。请帮我解决这个问题。

试试这个:

if (HttpContext.Current.Session.Contains("UserSession"))
{
  if (HttpContext.Current.Session["UserSession"] != null)
  {

  } 
} 

这意味着您的会话变量为空。
尝试使用缓存而不是会话,因为所有pc的会话值都不同?难道不是
?请阅读支票,让我们看看您的服务和网站。config@KamranShahid非常感谢你。链接工作正常。