How to delete ASP.NET temporary files from shared server

I got a request to look into the question, how do I delete temporary ASP.NET  files on a shared Windows hosting server and I’ve decided to take a look into it.

Unless you have access to the global temp used by the server – which any good sysadmin will not allow – you can’t clear the global temp. However what you can do is change the temporary directory path used by your application.

The web.config file allows you to make application specific configuration changes, including the .NET temp file path. You can instead change the path to a location you do control.

How? Using the compilation Element, but more specifically the tempDirectory attribute. This attribute has existed since .NET 1.1, so it will work on all .NET version from 1.1 through to at least .NET 4.

<compilation tempDirectory=”D:\userdata\client224\temp” />

This is important! Remember to correctly set NTFS and/or share permissions on the new tempDirectory location else your application will not compile. You’ll need to apply read/write (modify) permissions to the folder using the application pool identity. This identity may be a system user like NETWORKSERVICE, IIS AppPool\AppPoolNameHere or another custom identity. For more on application pool identities, check the official documentation.

It’s reasonable for Windows shared hosting providers to want to disable this ability – I would – but I’ve not read any instances of it happening yet.

Best of luck!

Similar Posts:

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
Tags: , , , .

What are your thoughts?