views:

1722

answers:

2

We have an ASP.NET application and I need to add a custom HTTP header to IIS for all the developers on the team, so I want to add a command in the NANT script that will add the HTTP Header when the build script is run. Is it even possible to do this from the command line.

I've been looking up the documentation on cscript adsutil.vbs but I can't find anything specfic to this issue.

A: 

If you can use Powershell there is plenty of information about using WMI objects to manage IIS. You can also write .NET command line helper apps that use IIS WMI objects and expose some function, like adding a custom HTTP header.

tarn
+1  A: 

Ok solution found. Clearly I wasn't looking hard enough, this is the command line to set the Custom HTTP Headers:

cscript adsutil.vbs set w3svc/HttpCustomHeaders "X-Powered-By: ASP.NET" "HeaderName2: value" "HeaderName3: value"

this needs to be run from the c:\Inetpub\AdminScripts folder.

As a bonus, here's the nant command to do it in a build script:

<exec workingdir="c:\Inetpub\AdminScripts" program="cscript.exe" commandline="adsutil.vbs set W3SVC/1/ROOT/Insurance/HttpCustomHeaders &quot;X-Powered-By: ASP.NET&quot; &quot;HeaderName2: value&quot; &quot;HeaderName3: value&quot;" />

via IIS troubleshooting, administration, and concepts.

Glenn Slaven