Sample Download: http://code.msdn.microsoft.com/CSAzureIncreaseTempFolderSi-d58c604d
By default the ASP.NET temp folder size in a Windows Azure web role is limited to 100 MB. This is sufficient for the majority of applications, but some applications may require more storage space for temp files. The sample demonstrates how to increase the ASP.NET temp folder size.
The sample was written by Microsoft Escalation Engineer Narahari Dogiparthi.
You can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage http://1code.codeplex.com/.
By default the ASP.NET temporary folder size in a Windows Azure web role is limited to 100 MB. This is sufficient for the vast majority of applications, but some applications may require more storage space for temporary files. In particular this will happen for very large applications which generate a lot of dynamically generated code, or applications which use controls that make use of the temporary folder such as the standard FileUpload control. If you are encountering the problem of running out of temporary folder space you will get error messages such as OutOfMemoryException or ‘There is not enough space on the disk.’.
This sample can be run as-is without making any changes to it.
1) In the ServiceDefinition.csdef create one LocalStorage resource in the Web Role, and set the Runtime executionContext to elevated. The elevated executionContext allows us to use the ServerManager class to modify the IIS configuration during role startup.
<WebRole name="IncreaseAspnetTempFolderSize" vmsize="Small">
<Runtime executionContext="elevated" />
<Binding name="Endpoint1" endpointName="Endpoint1" />
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
<LocalStorage name="AspNetTemp1GB" sizeInMB="1000" />
<Import moduleName="Diagnostics" />
2) Add reference to Microsoft.Web.Administration (location: <systemdrive>\system32\inetsrv) assembly and add below using statement to your project
3) Add the following code to the OnStart routine in WebRole.cs. This code configures the Website to point to the AspNetTemp1GB LocalStorage resource.
public override bool OnStart()
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
// Get the location of the AspNetTemp1GB resource
Microsoft.WindowsAzure.ServiceRuntime.LocalResource aspNetTempFolder =
//Instantiate the IIS ServerManager
ServerManager iisManager = new ServerManager();
// Get the website. Note that "_Web" is the name of the site in the ServiceDefinition.csdef,
// so make sure you change this code if you change the site name in the .csdef
Application app = iisManager.Sites[RoleEnvironment.CurrentRoleInstance.Id + "_Web"].Applications;
// Get the web.config for the site
Configuration webHostConfig = app.GetWebConfiguration();
// Get a reference to the system.web/compilation element
ConfigurationSection compilationConfiguration = webHostConfig.GetSection("system.web/compilation");
// Set the tempDirectory property to the AspNetTemp1GB folder
compilationConfiguration.Attributes["tempDirectory"].Value = aspNetTempFolder.RootPath;
// Commit the changes
For more information about the ASP.NET Temporary Folder see http://msdn.microsoft.com/en-us/magazine/cc163496.aspx