Training
Module
Customize Windows Server IaaS Virtual Machine images - Training
Learn to create new VMs from generalized images and use Azure Image Builder templates to create and manage images in Azure.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
by Fabio Yeon
This is a sample of how to write a native (C++) module that will dynamically insert an user-configured watermark into an image being served, as well as how to extend the configuration and the inetmgr UI tool to provide easy administration of the new module.
The watermark module has the following capabilities:
In order to compile the sample, you must install the Platform SDK for Windows Vista or Windows Server 2008. The project file included in the sample can be loaded in either Visual Studio 2005 or 2008.
The source code for these samples is available here.
The first component of this sample is the watermark module itself. It's a native C++ module that watches as requests are served, and if the MIME type of the request indicates it's an image, it will dynamically apply an user-configured watermark to the image, and replace the outgoing image. This is all done transparently in a module that runs after the request handler. To illustrate it:
Using the ATL's CImage classes makes loading and processing the image very simple, especially since it can manipulate various image formats easily.
Now, there are a few caveats in this sample and should be considered, especially if one wishes to use it in a "real" production environment:
The configuration of the watermark module is done via a new section in the "system.webServer" namespace. The schema file is as follow:
<configSchema>
<sectionSchema name="system.webServer/watermark">
<attribute name="enabled" type="bool" defaultValue="false" />
<attribute name="watermarkImage" type="string" />
<attribute name="transparency" type="uint" defaultValue="50" validationType="integerRange" validationParameter="0,100" />
<attribute name="position" type="enum" defaultValue="LowerRight" >
<enum name="UpperLeft" value="0" />
<enum name="UpperRight" value="1" />
<enum name="LowerLeft" value="2" />
<enum name="LowerRight" value="3" />
<enum name="Center" value="4" />
<enum name="Stretch" value="5" />
<enum name="Tile" value="6" />
</attribute>
</sectionSchema>
</configSchema>
The file "watermark.xml" should be dropped in the %windir%\system32\inetsrv\config\schema
directory for it to take effect, as well as adding the section definition in the "applicationhost.config" file, under the "system.webServer" namespace:
<section name="Watermark" overrideModeDefault="Allow" />
To use the module, one must then install the module in the global module list, "system.webServer\globalModules":
<add name="WatermarkModule" image="c:\Watermark\Watermark.dll" />
And to the module list for the application, "system.webServer\modules":
<add name="WatermarkModule" />
Along with the module sample, is a set of managed classes that are management plug ins to the new "Inetmgr" UI administration tool. There are various other documentations on how to write and extend the new "Inetmgr", which are available here. In short, to use them, one needs to build, add the dlls to the GAC (Global Assembly Cache), and add the following configuration to the %windir%\system32\inetsrv\config\administration.config
file:
In the <moduleProviders> collection, add the following entry:
<add name="Watermark" type="WatermarkServer.WatermarkModuleProvider, Watermarkserver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5f6f8f3f74d67fe4" />
And add the following line to the <modules>
collection:
<add name="Watermark" />
Restart the tool and a new icon should be available in your site.
Training
Module
Customize Windows Server IaaS Virtual Machine images - Training
Learn to create new VMs from generalized images and use Azure Image Builder templates to create and manage images in Azure.