How to add custom HTTP Headers to IIS from the command line

孤街浪徒 提交于 2019-12-21 06:35:10

问题


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 &quot;X-Powered-By: ASP.NET&quot; &quot;HeaderName2: value&quot; &quot;HeaderName3: value&quot;" />

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!