Saving Image To a Temp Folder is Loosing Session

457 views Asked by At

I have a method that saves an image to a temp folder:

System.Web.HttpContext.Current.Server.MapPath("~/bin/temp/")

I debugged each line, and I am sure that the following line is making my application restart, so it is loosing my session:

bitmap.Save(pathProcessedImage);

After this method is executed, the Global.asax.cs trigger these events:

Session_End
Application_Start
Session_Start

What can I do?

1

There are 1 answers

1
Steve On BEST ANSWER

Storing temporary data in the bin folder doesn't seem to be a good idea. This folder is used to store the binary assemblies used by your ASP application and it is (by default) write protected to avoid hacking. Subfolders created there (if you are able to do it) should take the same restriction of the parent folder. It would be better to store temporary data in the APP_DATA folder that is precisely created for this kind of data.

However, storing data in a path where you don't have permissions should result in a very visible and clear exception. If you don't see it, then I think that you have used an empty try/catch to hide exceptions. Check your code because hiding exceptions is very wrong