I’m using ASP.net MVC 3 and the ASP.net Development Server.
My web app downloads image files from Amazon S3 into a session folder. A user then sees the images in their browser because one of the app’s web pages references the images.
If I then delete the contents of the session folder and re-download the images the application restarts.
It only seems to restart if I’ve looked at the images files in a web page and delete them before re-downloading them. So if I don’t look at them in a web page I can delete them, do the download again and the app won’t restart. Similarly, if I view them in a web page, don’t delete them and just write over them when doing the download, the app doesn’t restart.
Any ideas if there’s a way I can, say, delete them so that the web server doesn’t mind if I then re-download them?
I don’t want to lose the session you see.
Here is the deletion code…
public static void EmptyFolder(string directory)
{
if (!Directory.Exists(directory))
{
return;
}
DirectoryInfo directoryInfo = new DirectoryInfo(directory);
EmptyFolder(directoryInfo);
}
private static void EmptyFolder(DirectoryInfo directoryInfo)
{
foreach (FileInfo file in directoryInfo.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo subfolder in directoryInfo.GetDirectories())
{
EmptyFolder(subfolder);
subfolder.Delete();
}
}
This is expected behaviour; If you delete a file that exists in the folder context of the website, IIS will restart in-case it has to dynamically recompile anything.
It’s the same as saving a change to Web.Config.
If this is too much of a problem, you need to move the images outside of the Website folder.
Regarding the Session, you can either move the resources like I suggested, or consider switching to SQL session storage, or using the ASP.Net session service; which disconnects it from the website.
Loading the image in a browser causes IIS to bind it to your worker process, likely because of caching, but it’s relevant I guess to ask where the session folder is.
Does your folder structure look similar to this ?
or this ?