I've created a class named MyLongRunningClass
that contain a method bellow:
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;
}
From the controller this method is called with list of file to save in images directory. whenever HttpContext.Current.Server.MapPath("~//Content//images//"+file.FileName)
is executed NullReferenceException
thrown, and HttpContext.Current
is always null
. Same thing happen when I use session. I don't know whats wrong with the code.