As you may know, you can use appcmd.exe application to configure IIS and when you are using Web Role in your Azure Application, it is possible that you may need to configure IIS before the role starts. You can use startup task method to launch appcmd.exe to perform such configuration. To learn more about Windows Azure startup task click here..
For example we want to add dynamic compression for “Application/soap+xml” MIME type and static compression for “text/xml” MIME type. Here are the detailed steps to configure these settings using AppCmd process:
1. Create a folder name Startup in your Project
2. Create a command batch file name launchappcmd.cmd in the same folder and add following command:
appcmd set config /section:httpCompression /+staticTypes.[mimeType='text/xml',enabled='true'] /commit:apphost
appcmd set config /section:httpCompression /+dynamicTypes.[mimeType='application/soap+xml’,enabled='true'] /commit:apphost
At this point your VS2010 based application will look like as below:
3. Now add the following code in your Service Definition (ServiceDefinition.csdef):
<Task commandLine="Startup\LaunchAppCmd.cmd" executionContext="elevated" taskType="simple">
That’s it!! Now you can verify that IIS configuration file has above configuration settings, by RDP to your Azure VM.
It is important to remember to set the "LaunchAppCmd.cmd" "Copy to output Directory" property to "always", otherwise the file will not be part of the package.
What would the command look like if you have multiple static mimetypes?