Saturday, March 17, 2012

Howto: configure WebDAV on Windows Azure WebRole instance automatically in deployment package

Last blog entry we configured WebDAV on a WebRole manually. Unfortunately the settings are gone once the WebRole is migrated, re-deployed etc. All the settings must be prepared again.

To avoid this we created a startup task performing all the configuration steps and built it in the deployment.

The steps:

Create a StartupWebDAV.cmd script with following content:

rem configure WebDAV

rem activate WebDAV feature
CMD /C START /w PKGMGR.EXE /l:log.etw /iu:IIS-WebDAV

rem enable WebDAV on the default website
%windir%\system32\inetsrv\AppCmd set config /section:system.webServer/webdav/authoring /enabled:true /commit:apphost

rem set SSL for WebDAV
%windir%\system32\inetsrv\AppCmd set config /section:system.webServer/webdav/authoring /requireSsl:false /commit:apphost

rem set WebDAV authorization rule
rem here: read/write/source for user webdavAdministrator on any path

%windir%\system32\inetsrv\AppCmd set config /section:system.webServer/webdav/authoringRules /+[users='webdavAdministrator',path='*',access='Read,Write,Source'] /commit:apphost

rem enable Windows Authentication
%windir%\system32\inetsrv\Appcmd set config /section:windowsAuthentication /enabled:true

Note following aspects:

  • activation of WebDAV feature logs the events in log.etw file
  • the appcmd set config does not specify Website – the default and only Website assumed; if you have many Websites and want to specify a dedicated one, you need to extend the commands with Website specification – refer to appcmd manual
  • the user name in the sample – webdavAdministrator – must be replaced by real name(s), the user(s) must exist as OS user(s)

Bind the script as startup task in .csdef (service definition) file:

    <Startup>
<
Task commandLine="StartupWebDAV.cmd" executionContext="elevated" taskType="simple" />
</
Startup>


Build, package, deploy, enjoy…

No comments: