如果使用var存储,如何在c#中存储和获取存储数据到会话中

时间:2016-04-29 05:20:21

标签: c# class session var class-library

我从网络服务获取数据,例如关注

 string serviceUrl = "https://www.mscholid.com/assings/handlqueryrs/myprod.ashx";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serviceUrl);
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            StreamReader sr = new StreamReader(resp.GetResponseStream());
            string result = sr.ReadToEnd();
            sr.Close();


            var rootResult = XElement.Parse(result);

现在我想将这个根结果放入会话

会话[" rootv"] = rootResult;

然后我想要检索它。 商店功能应该在课堂内进行

  public class NileResult
    {


        public dynamic nilecruiseFinalData_Images(string selectedID)
        {
            string serviceUrl = "https://www.mscholid.com/assings/handlqueryrs/myprod.ashx";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serviceUrl);
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

            StreamReader sr = new StreamReader(resp.GetResponseStream());
            string result = sr.ReadToEnd();
            sr.Close();


            var rootResult = XElement.Parse(result);
//in here  I want to store in to a session
 }
}

我该怎么办呢。

1 个答案:

答案 0 :(得分:1)

要访问请求的会话,您可以使用:

HttpContext.Current.Session["rootv"] = rootResult;

HttpContext.Current是请求的当前上下文。