[英]Error using session in WCF Service
I am using the below sample function in wcf project. 我在wcf项目中使用以下示例函数。 It's working fine internally.
内部运行良好。 When i am calling this function from outside of the hosted service.
当我从托管服务外部调用此函数时。 It returns the error.
它返回错误。
Object reference not set to be an instance of an object.
I find that line HttpContext.Current.Session["UserSession"] // Error Code 我发现那条线HttpContext.Current.Session [“ UserSession”] //错误代码
try
{
if (HttpContext.Current.Session["UserSession"] != null)
{
}
else
{
}
}
catch(Exception ex)
{
return ex.Message;
}
But i want to user the session variable. 但是我想使用会话变量。 Please help me to solve this.
请帮我解决这个问题。
Try this : 尝试这个 :
if (HttpContext.Current.Session.Contains("UserSession"))
{
if (HttpContext.Current.Session["UserSession"] != null)
{
}
}
It means your session variable is empty. 这意味着您的会话变量为空。 Try using cache instead of session as session value is different for all pc's
尝试使用缓存而不是会话,因为所有PC的会话值都不同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.