如果使用 var 存储,如何在 c# 中将存储的数据存储和获取到会话中
how to store and get stored data in to a session in c# if it stored using var
我正在从网络服务获取数据,如下所示
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;
那我要找回它。
存储函数应该在 class
中执行
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
}
}
我该怎么做。
要访问请求的会话,您可以使用:
HttpContext.Current.Session["rootv"] = rootResult;
HttpContext.Current 是请求的当前上下文。
我正在从网络服务获取数据,如下所示
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;
那我要找回它。 存储函数应该在 class
中执行 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
}
}
我该怎么做。
要访问请求的会话,您可以使用:
HttpContext.Current.Session["rootv"] = rootResult;
HttpContext.Current 是请求的当前上下文。