1

I have a small asp.net MVC 1 web app that can store files and create directories in the App_Data directory. When the write operation succeeds, I add a message to the tempdata and do a redirectToRoute. The problem is that the tempdata is null when the action is executed. If i write the files in a directory outside of the web applications root directory, the tempdata is not null and everything works correctly. Any ideas why writing in the app_data seems to clear the tempdata ?

edit: if DRS.Logic.Repository.Manager.CreateFile(path, hpf, comment) writes in the App_Data, TempData will be null in the action being redirected to. if it is a directory out of the web app root it is fine. No exceptions are being thrown.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(int id, string path, FormCollection form)
{
    ViewData["path"] = path;
    ViewData["id"] = id;

    HttpPostedFileBase hpf;

    string comment = form["FileComment"];
    hpf = Request.Files["File"] as HttpPostedFileBase;

    if (hpf.ContentLength != 0)
    {
        DRS.Logic.Repository.Manager.CreateFile(path, hpf, comment);
        TempData["notification"] = "file was created";
        return RedirectToRoute(new { controller = "File", action ="ViewDetails", id = id, path = path + Path.GetFileName(hpf.FileName) });
    }
    else
    {
        TempData["notification"] = "No file were selected.";
        return View();
    }
}
DaveRandom
  • 87,921
  • 11
  • 154
  • 174
RAMX
  • 11
  • 3
  • Please post the code, are you still using RedirectToRoute when you are writing to a different directory? – Lazarus Nov 10 '09 at 13:44
  • yes I still use redirecttoroute. the code that writes the actual file is straightforward and does not throw any exceptions. We tried redirectToAction with the same results. – RAMX Nov 10 '09 at 14:24

1 Answers1

1

Figured out what was causing tempdata to become null. DRS.Logic.Repository.Manager.CreateFile(path, hpf, comment); creates a temp directory under ~/App_Data/, writes a file in that directory, commits that file to a repository and then cleans up the temp directory. It seems that certain io operations within App_Data trigger the filesystem monitor and the web application is restarted. I was using an inproc session so when the application would restart, the session would be cleared. Tempdata is actually stored in the session so it was cleared as well. solution: dont use inproc session or store files outside of the web application's root directory. I had no idea that changes under App_data triggered an application restart.

RAMX
  • 11
  • 1
  • 1
    Huh. You say writing to app_data caused the application restart? What are the certain IO operations? It would be interesting to see what ASP.Net actually reported: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx – a7drew Jun 29 '10 at 23:51
  • 2
    It seems that the IO operation causing the restart is deleting a folder. – jhexp Aug 10 '10 at 12:36
  • gone through with the same scenario. But my case was in the bin folder i try to create a folder and write files inside it but it causes the concurrent dictionary to be always null – ECie Mar 19 '15 at 07:12