Writing files in App_Data causes tempdata to be null
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();
开发者_开发知识库 }
}
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.
精彩评论