Monday, March 19, 2012

Failed file operations with WebDAV using customer error pages on 404 (Not Found)

 

If you configure custom error pages for 404 (Not Found) as redirect to an URL inside the Website may cause problems with file operations via WebDAV.

This setting may be configured using IIS Manager:

image

or with directly editing the Web.config:

<httpErrors>
        <remove
               statusCode="404"
               subStatusCode="-1"/>
        <error 
               statusCode="404"
               prefixLanguageFilePath=""
               path="/index.html" 
              
responseMode="ExecuteURL"/>
  </httpErrors>

When the default 404 handling error pages are configured as above you may encounter problems using WebDAV file operations:

image

image

“File too large”

image

“The parameter is incorrect”

The solution is: each before starting a WebDAV file operation toggle the redirection setting at least fir “Not found” (404) off, perform required file operation and revert the redirection configuration.

Enjoy!

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…

Friday, March 16, 2012

Howto: configure WebDAV on Windows Azure WebRole instance

 

One day you may decide to configure WebDAV on your Windows Azure WebRole instance: for example, to perform file uploads without Azure deployments. BTW, be aware: all uploaded to WebRole instance files which do not exist in the deployment package are irreversible gone when the instance is migrated to another Azure host node or restarted.

But while the instance is running you may use the files uploaded via WebDAV.

Why we use WebDAV on Azure? Well, there was a business process to upload the Web content files to the former hosting platform prior to Windows Azure. The deployment chain includes a WebDAV upload and the tools are configured. Additionally,the uploaded files can be used immediately.With an usual Azure deployment package there is an instance outage for approximately 10-15 minutes. We need to update the files multiple times a day and use WebDAV to provide quick access to updated content files. Once uploaded via WebDAV the files can be accessed immediately. Additionally we update these files to deployment package and deploy then this package overnight while the outage of instance is not so critical.

Here are steps to activate and configure WebDAV on Windows Azure WebRole.

Configure Windows Server 2008 R2 as instance OS

First, be sure you use Windows Server 2008 R2 as instance OS. Windows Server 2008 has no WebDAV setup package out-of-box and requires download and setup of WebDAV modules. Windows Server 2008 R2 has WebDAV setup as feature package and requires only activation and configuration.

To ensure and configure right version of OS launch Windows Azure management portal and open popup menu on the selected deployment:

image

In popup menu select “Configure OS”:

image

You may see Windows Server 2008 SP2 as current OS version:

image

Select “Windows Server 2008 R2” and confirm with “OK”:

image

The system needs some time to be reconfigured:
image

All instances will be updated:

image

After all the instances are reconfigured you may use RDP to open terminal session to each instance to ensure configured OS version. The manual for RDP configuration on Azure is here: http://msdn.microsoft.com/en-us/library/windowsazure/gg443832.aspx

You will need RDP to each instance for WebDAV configuration. Use “Connect” button in management portal:

image

You should see the server configuration window with the current OS version information:

image

Alternatively you can start “winver”:
image

…and see the OS version:
image

Activate WebDAV

WebDAV is a feature of IIS and can be activated via Server Manager:

image

Select “WebDAV” in Role Services:

image

Confirm installation:

image

The installation process begins:

image

Configure WebDAV

Configure WebDAV for Website using IIS Manager:

image

Select “WebDAV Authorization rules” in IIS features of the Website:image

Enable WebDAV for the Website:

image

Once WebDAV is enabled, the option to disable WebDAV appears:

image

Add authorization rule to provide access to the file system, select content type, user(s) and permissions:

image

Review configured rules:

image

Do not forget to enable Windows Authentication on Website – otherwise the WebDAV users cannot login. Use “Authentication” IIS feature of the  Website:

image

Enabled Windows Authentication looks like:

image

Complete!

Access WebRole instance using WebDAV

From now you can access file system on WebRole instance using WebDAV. On the client open Windows Explorer:

image

Select “Map network drive”:

image

Select “Connect to a Web site…”:

image

Add network location:

image

Specify URL to the WebRole where WebDAV is enabled and configured:

image

Enter user login and password when prompted (use credentials you configured in WebDAV authorization rules):

image

Windows Explorer opens the location you configured:

image

You can use ordinary file system functions to upload to or download from WebRole instance.

Enjoy!

Tuesday, March 06, 2012

WMI error: Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa

 

We used WMI from ASP.NET code to get CPU(s) ID for the current host. It worked a while, but suddenly stopped – with message:

Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa

Reload user profile for AppPool identity – as described here – didn’t help.

Once downloaded and run WMIDiag the system came back to running state.