我创建了一个名为MyLongRunningClass的类,它包含一个方法:
@H_502_2@public string ProcessLongRunningAction(IEnumerable<HttpPostedFileBase> files,string id)
{
int currentIndex = 0;
foreach (HttpPostedFileBase file in files)
{
currentIndex++;
lock(syncRoot)
{
string path=HttpContext.Current.Server.MapPath("~//Content//images //"+file.FileName);//Excecption is created here........
file.SaveAs(path);
}
Thread.Sleep(300);
}
return id;
}
从控制器调用此方法,使用文件列表保存在images目录中.每当执行HttpContext.Current.Server.MapPath(“〜// Content // images //”file.FileName)时,抛出NullReferenceException,并且HttpContext.Current始终为null.当我使用session时会发生同样的事情.我不知道代码有什么问题.