2016-11-08 57 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(); 
    } 

    }