我创建了一个名为MyLongRunningClass包含方法的类:
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;
}
Run Code Online (Sandbox Code Playgroud)
从控制器调用此方法,使用文件列表保存在images目录中.无论何时HttpContext.Current.Server.MapPath("~//Content//images//"+file.FileName)被执行NullReferenceException抛出,HttpContext.Current总是如此null.当我使用session时会发生同样的事情.我不知道代码有什么问题.
| 归档时间: |
|
| 查看次数: |
14714 次 |
| 最近记录: |