2016-11-08 56 views
0

我创造的mvc5一个Web应用程序中,我传递我的登录信息通过会话Web服务使用会话

 if (pm != null) 
     { 
      string pm1 = pm.ToString(); 
      HttpContext.Current.Session["pm"] = pm1.ToString(); 
     } 

这里如果我string pmnot null然后串点的值将是保存在我的会议,但我得到的错误,当我跑我的web服务

System.NullReferenceException:对象不设置到对象的实例 。

有没有其他方法可以做到这一点?

+0

从那里您将数据保存到会话? – faisal1208

回答

0

为此,你需要启用WebMethod属性 会话,然后使用

String.IsNullOREmpty(pm) 

    [webmethod(EnableSession = true)] 
    public string your method name 
    { 
     if (pm != null) 
    { 
     string pm1 = pm.ToString(); 
     HttpContext.Current.Session["pm"] = pm1.ToString(); 
    } 

    }