如何使用MSBuild修改远程IIS6网站的自定义错误

时间:2009-12-15 15:23:09

标签: iis-6 build-automation msbuild-task microsoft.sdc.tasks

我正在尝试使用“Microsoft.Sdc.Tasks.Web.Website.UpdateHttpErrorSetting”来更改远程IIS网站的http错误消息。特别是这个任务的文档有点缺乏,我还没有找到成功使用它的方法。我希望http 404错误加载网址而不是默认的404b.html文件。我已经尝试过这样的任务:

<Microsoft.Sdc.Tasks.Web.Website.UpdateHttpErrorSetting
  ErrorCode="404"
  MachineName="$(MachineName)"
  WebSiteName="$(SiteName)"
  Path="."
  Uri="/errors/mycustom404.htm"
  Type="URL"
  DirectoryType="WebDir" />

当任务运行时我得到一个异常,但我不清楚我缺少什么:

Using "Microsoft.Sdc.Tasks.Web.Website.UpdateHttpErrorSetting" task from assembly "c:\Microsoft.Sdc.Tasks.dll".
Task "Microsoft.Sdc.Tasks.Web.Website.UpdateHttpErrorSetting"
 error : A task error has occured.
 error : Message       = Object reference not set to an instance of an object.
 error : ErrorCode     = 404
 error : SubErrorCode  = <String.Empty>
 error : Uri           = /errors/mycustom404.htm
 error : Type          = URL
 error : DirectoryType = WebDir
 error : MachineName   = testMachineName
 error : WebSiteName   = testSiteName
 error : Path          = .
 error : DirectoryName = <String.Empty>
 error : 
 error :    at Microsoft.Sdc.Tasks.Web.WebSite.UpdateHttpErrorSetting.InternalExecute()

非常欢迎进一步的见解。

1 个答案:

答案 0 :(得分:0)

正如我想象的那样,我对任务的使用是不正确的。像404这样的顶级HTTP错误要求您指定SubErrorCode "*"的值:

<Microsoft.Sdc.Tasks.Web.Website.UpdateHttpErrorSetting
  ErrorCode="404"
  SubErrorCode="*"
  MachineName="$(MachineName)"
  WebSiteName="$(SiteName)"
  Path="."
  Uri="/errors/mycustom404.htm"
  Type="URL"
  DirectoryType="WebDir" />

这实际上是在SubErrorCode属性的文档中。

如果未指定或不正确,则由任务在计算机的http errors集合上执行的查找引起空引用。没有检查返回的null。