IIS7 / appcmd – 导入httpErrorconfiguration出错

为了尽量避免为我们的应用程序configurationIIS,我一直在寻找appcmd。 具体来说,这是能够导出configuration树,并重新应用他们最小的麻烦。

一般来说,这给出了导出的configuration:

appcmd list Config /section:httpProtocol /config /xml > template.xml 

然后我可以在以后重新导入:

 appcmd set Config /in < template.xml 

并且更改得到应用。 这适用于除自定义错误页面以外的其他所有内容。

我已经导出这些:

 appcmd list Config "Default Web Site/intranet" /section:httpErrors /config /xml > customerrors.xml 

但是当我尝试导入:

 appcmd set Config /in < customerrors.xml 

我得到以下错误:

 ERROR ( hresult:8007000d, message:The input contained an error element, which may indicate that the operation producing the input has failed. ) 

那么是的,那是因为我正在导入看起来像这样的errohandler条目:

 <?xml version="1.0" encoding="UTF-8"?> <appcmd> <CONFIG CONFIG.SECTION="system.webServer/httpErrors" path="MACHINE/WEBROOT/APPHOST/Default Web Site/intranet" overrideMode="Inherit" locked="false"> <system.webServer-httpErrors errorMode="Custom"> <error statusCode="500" prefixLanguageFilePath="" path="/intranet/ErrorPages/500-100.asp" responseMode="ExecuteURL" /> <error statusCode="500" subStatusCode="100" path="/intranet/ErrorPages/500-100.asp" responseMode="ExecuteURL" /> </system.webServer-httpErrors> </CONFIG> </appcmd> 

…这是appcmd给了我什么(这意味着“错误”元素真的是需要的)。 这是一个appcmd试图太聪明,还是我错过了一些可笑的明显?

干杯!

滑稽。 所以appcmd导入似乎将“错误”一词视为一个真正的错误,而不是说明这种合法的情况。 我会看看是否可以find更多关于你的信息。

至于解决scheme,在appcmd中,查找语法的最佳方法是使用configuration编辑器。 进行所需的更改,然后转到右侧的“生成脚本”,然后单击AppCmd选项卡。 获得你需要的语法是一个很好的技巧。

下面是一个如何执行httpErrors的例子:

 appcmd.exe set config "Default Web Site" -section:system.webServer/httpErrors /+"[statusCode='503',path='503.htm']"