问题
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.
回答1:
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 "X-Powered-By: ASP.NET" "HeaderName2: value" "HeaderName3: value"" />
via IIS troubleshooting, administration, and concepts.
回答2:
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.
来源:https://stackoverflow.com/questions/637289/how-to-add-custom-http-headers-to-iis-from-the-command-line