views:

272

answers:

3

I have a .NET app that allows users to upload images to a directory within the webapp and then view them. The problem is that the session gets lost when I upload or delete an image in the webapp directory. It seems that the app pool is getting recycled when I add images, and not just config or cs files.

I have seen this technique used in so many tutorials that I wonder if it does actually work with the right server settings, or if it is a completely flawed technique.

If I add an image to a subdirectory manually, or delete it manually, the session remains. If I add the image to a subdirectory through visual studio the session remains, but if I delete it through visual studio, the session is lost.

If I upload the images to a folder outside of the webapp then I can't show them in img tags.

I'd be interested to hear what you might do as a workaround.

+1  A: 

Try storing the Session in an out of state process. You can do this by starting the "ASP.Net State Service" in the Services screen of "Administrative Tools" and then using this line in your web.config:

<sessionState
      mode="StateServer"
      stateConnectionString="tcpip=127.0.0.1:42424"
      cookieless="false"
      timeout="20" />

This will allow your sessions to persist, even if you reset IIS.

iZ
A: 

You can store information such as an Image ID in an asp:HiddenField or as a .Attribute[] in a control. When I need to bind a button to a specific item in a list, for example, I give the button an Attribute that reflects the ID of the item in question. I use HiddenFields for other info that doesn't have one associated control (i.e. Post IDs, etc).

tsilb
+1  A: 

I'd check the event log to make sure something you are doing isn't crashing the AppPool

StressChicken