【发布时间】:2013-03-04 07:26:17
【问题描述】:
使用 HttpContext.Current.Items 我们可以访问当前请求中的变量
我的问题是,如果请求移动到不同的线程,我们还能访问它吗?
如果是,我们如何访问它?
我假设它会抛出空引用异常?
我正在尝试使用下面的代码,但它会引发 Null Ref Exception
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnClick(object sender, EventArgs e)
{
HttpContext.Current.Items["txtbox1"] = txtbox1.Value;
var t = new Thread(new Threadclas().Datamethod());
t.Start();
}
}
public class Threadclas
{
public void Datamethod()
{
var dat = HttpContext.Current.Items["txtbox1"];
**//how can i access HttpContext here** ?
}
}
【问题讨论】:
标签: asp.net