title: Why HttpContext.Current always null in user defined class in asp.net mvc?
body: <p>I've created a class named <code>MyLongRunningClass</code> that contain a method bellow:</p>
  
  <pre><code> public string ProcessLongRunningAction(IEnumerable&lt;HttpPostedFileBase&gt; 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;
      }
  </code></pre>
  
  <p>From the controller this method is called with list of file to save in images directory. whenever <code>HttpContext.Current.Server.MapPath("~//Content//images//"+file.FileName)</code> is executed <code>NullReferenceException</code> thrown, and <code>HttpContext.Current</code> is always <code>null</code>. Same thing happen when I use session. I don't know whats wrong with the code.</p>