2011-03-15 33 views
9

我想調用需要從服務器讀取文件的異步方法。只要方法是異步,HttpContext.Current就會變爲空。如果我通常打電話,它工作正常。我該如何解決這個問題?使用異步時HttpContext.Current爲空

我的代碼是:

System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(path)) 
+0

這可能幫助:HTTP ://www.rahulsingla.com/blog/2010/09/asp-net-httpcontext-current-is-null-in-endxxx-method-of-asynchronous-web-methods-pair – Robert 2011-03-15 20:22:04

回答

3

Thaks的小費BVS。

正確的類調用是HostingEnvironment.MapPath(path);

相關問題