-
Notifications
You must be signed in to change notification settings - Fork 652
Xdt transform samples
Note: this section applies to both Pre-Installed and Private site extensions.
The simplest way to apply one of these transforms for your site is:
- Create an
applicationHost.xdt
file under your 'site' folder, and copy the content below into it
See Xml Document Transform for detailed documentation on the XDT syntax.
The following will inject an environment variable named FOO
, with value BAR
:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="Insert" >
<environmentVariables>
<add name="FOO" value="BAR" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>
You may wonder how Kudu or other extensions gets set up in the SCM site. The key is the applicationHost.xdt (notice one exists for each versioned folders). The Xml Document Transform file is used to transform the actual applicationHost.config for the site.
This transform adds a /somepath IIS application under the SCM site.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<sites>
<site name="%XDT_SCMSITENAME%" xdt:Locator="Match(name)">
<application path="/somepath" xdt:Transform="Insert">
<virtualDirectory path="/" physicalPath="%XDT_EXTENSIONPATH%" />
</application>
</site>
</sites>
</system.applicationHost>
</configuration>
It is a variation of the above but simply adds a /somepath IIS application under the main site (%XDT_SITENAME%
) instead.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<sites>
<site name="%XDT_SITENAME%" xdt:Locator="Match(name)">
<application path="/somepath" xdt:Transform="Insert">
<virtualDirectory path="/" physicalPath="%XDT_EXTENSIONPATH%" />
</application>
</site>
</sites>
</system.applicationHost>
</configuration>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<sites>
<site name="%XDT_SITENAME%" xdt:Locator="Match(name)">
<limits xdt:Transform="Remove" />
<limits xdt:Transform="Insert" maxUrlSegments="64" />
</site>
</sites>
</system.applicationHost>
</configuration>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<httpCompression>
<dynamicTypes>
<add mimeType="application/foo" enabled="true" xdt:Transform="Insert" />
</dynamicTypes>
</httpCompression>
</system.webServer>
</configuration>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<httpCompression xdt:Transform="SetAttributes(noCompressionForProxies)" noCompressionForProxies="false" >
</httpCompression>
</system.webServer>
</configuration>
Remove all your recycling options from your .NET 4(+) application pool, and make it available always
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<applicationPools>
<add name="%XDT_SITENAME%" xdt:Transform="Insert" autoStart="true" managedRuntimeVersion="v4.0" startMode="AlwaysRunning">
<processModel idleTimeout="00:00:00" />
<recycling>
<periodicRestart time="00:00:00" />
</recycling>
</add>
</applicationPools>
</system.applicationHost>
</configuration>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<applicationPools>
<add name="%XDT_SITENAME%" xdt:Locator="Match(name)">
<recycling xdt:Transform="Insert" >
<periodicRestart>
<schedule>
<clear />
<add value="00:00:00" />
</schedule>
</periodicRestart>
</recycling>
</add>
</applicationPools>
</system.applicationHost>
</configuration>
Note: the default is 1000
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<applicationPools>
<add name="%XDT_SITENAME%" xdt:Locator="Match(name)" xdt:Transform="SetAttributes(queueLength)" queueLength="5000">
</add>
</applicationPools>
</system.applicationHost>
</configuration>
This transform finds the <application>
tag that has the v5.4 full path, and adds a new queueLength
attribute to it.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<fastCgi>
<application xdt:Locator="Match(fullPath)" xdt:Transform="SetAttributes(queueLength)"
fullPath="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe" queueLength="5000"/>
</fastCgi>
</system.webServer>
</configuration>
This transform changes the value of maxInstances
for PHP 5.4.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<fastCgi>
<application xdt:Locator="Match(fullPath)" xdt:Transform="SetAttributes(maxInstances)"
fullPath="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe" maxInstances="8"/>
</fastCgi>
</system.webServer>
</configuration>
e.g. this enables parent paths
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<asp xdt:Transform="SetAttributes(enableParentPaths)" enableParentPaths="true" />
</system.webServer>
</configuration>
e.g. this enables native module (native module must be registered at globalModules)
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<globalModules>
<add name="Your Module Name" image="<path to dll such as d:\home\SiteExtensions\MyNative\module.dll>" preCondition="bitness32" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</globalModules>
</system.webServer>
</configuration>
e.g. this enables SomeModule on the main site
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location path="%XDT_SITENAME%" xdt:Locator="Match(path)">
<system.webServer>
<modules>
<add name="SomeModule" type="SomeModule.SomeModuleType" xdt:Transform="InsertIfMissing"/>
</modules>
</system.webServer>
</location>
</configuration>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<security>
<isapiCgiRestriction xdt:Transform="SetAttributes(notListedIsapisAllowed)" notListedIsapisAllowed="true"/>
</security>
</system.webServer>
</configuration>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<security>
<ipSecurity xdt:Transform="RemoveAttributes(allowUnlisted)">
<add ipAddress="204.79.197.200" allowed="true" xdt:Transform="Insert"/>
</ipSecurity>
</security>
</system.webServer>
</configuration>
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<httpLogging xdt:Transform="SetAttributes(selectiveLogging)" selectiveLogging="LogSuccessful" />
</system.webServer>
</configuration>
The following does the equivalent of enabling Web Sockets in the portal
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<globalModules>
<add name="WebSocketModule" xdt:Locator="Match(WebSocketModule)" xdt:Transform="Remove" />
<add name="WebSocketModule" image="%windir%\System32\inetsrv\iiswsock.dll" xdt:Transform="Insert" />
</globalModules>
<webSocket xdt:Transform="SetAttributes(pingInterval)" pingInterval="00:02:30" />
</system.webServer>
<location path="" xdt:Locator="Match(path)" xdt:Transform="InsertIfMissing">
<system.webServer xdt:Transform="InsertIfMissing">
<modules xdt:Transform="InsertIfMissing">
<add name="WebSocketModule" xdt:Locator="Match(WebSocketModule)" xdt:Transform="Remove" />
<add name="WebSocketModule" lockItem="true" xdt:Transform="Insert" />
</modules>
</system.webServer>
</location>
</configuration>
Add a rule that returns a 403 if a certain http header is present
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer xdt:Transform="InsertIfMissing">
<rewrite xdt:Transform="InsertIfMissing">
<rules xdt:Transform="InsertIfMissing">
<rule name="MyRule" xdt:Locator="Match(name)" xdt:Transform="RemoveAll"/>
<rule name="MyRule" xdt:Locator="Match(name)" patternSyntax="Wildcard" stopProcessing="true" xdt:Transform="InsertIfMissing">
<match url="*" />
<conditions>
<add input="{HTTP_X_FORWARDED_SSL30}" pattern="1" />
</conditions>
<action type="CustomResponse" statusCode="403" subStatusCode="900" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>