Creating temporary files in wwroot folder ASP.Net

2019-08-28 20:35发布

问题:

I have developed an application in which some pdf reports are generated in a temporary folder. The temp folder is located inside the wwroot folder. Now, sometimes the session gets destroyed as soon as a pdf is generated.

Is this caused due to temp file generation ? Should the temp folder be outside wwroot folder ?

回答1:

Yes, you should place that folder outside the root folder.

The reason your session gets destroyed is because IIS restarts the application when 15 files are modified. An easy workaround is to create a virtual directory in IIS, pointing to a folder outside the root and then write the files to that directory.

That way, your website doesn't need any hard references to a folder but can use MapPath to map the virtual directory to a physical folder



回答2:

Why not use the App_Data folder? It's much more simple and you will not have this kind of problem.



回答3:

I finally added a folder outside the wwwroot folder, linked it via virtual directory which solved the problem.