Writing files in App_Data causes tempdata to be null

Posted by RAMX on Stack Overflow See other posts from Stack Overflow or by RAMX
Published on 2009-11-10T13:41:22Z Indexed on 2010/04/02 1:03 UTC
Read the original article Hit count: 567

Filed under:
|
|
|

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();
    }
}

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc