2013-09-23 38 views
0

我正在对使用HttpContext获取和设置会话变量的方法进行异步调用。但是当我正在使用它时,HttpContext显示为空。那么我如何使用HttpContext?如何使用HttpContext进行异步调用

代码:

public void SessionsFetchAllWatchNowAsync() 
     { 
      string aaa = Convert.ToString(HttpContext.Current.Session["UserID"]); 


     } 
     protected void Page_Load(object sender, EventArgs e) 
     { 

      Session[Utility.UserID] = 0; 
      Action<StartPage> notifyTask = null; 
      notifyTask = new Action<StartPage>((o) => new StartPage().SessionsFetchAllWatchNowAsync()); 
      if (notifyTask != null) 
       notifyTask.BeginInvoke(null, null, null); 
     } 

感谢,

Dalvir

回答

1

HttpContext.Current设置的线程上,这意味着你必须把它传递到您的异步方法才能使用它因为处理异步方法的线程不是ASP.NET为处理请求而创建的线程。