【问题标题】:Error using session in WCF Service在 WCF 服务中使用会话时出错
【发布时间】:2014-03-14 11:13:05
【问题描述】:

我在 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;
}

但我想使用会话变量。请帮我解决这个问题。

【问题讨论】:

标签: c# asp.net web-services wcf c#-4.0


【解决方案1】:

试试这个:

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

  } 
} 

【讨论】:

    【解决方案2】:

    这意味着您的会话变量为空。 尝试使用缓存而不是会话,因为所有电脑的会话值都不同

    【讨论】:

      猜你喜欢
      • 2015-03-10
      • 2011-08-27
      • 2011-08-06
      • 2013-05-28
      • 2011-08-06
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多