【发布时间】:2011-06-09 16:36:54
【问题描述】:
我正在尝试为我的 Web 应用程序设置自定义 404 错误页面。问题是这个应用程序将被部署到许多不同的环境中。有时它会在虚拟目录中,有时则不会。
我在名为 ErrorPages 的目录中有错误页面,并且我的配置设置如下:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="/VirtualDir/ErrorPages/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
问题是当我将它部署到网站的根目录时,需要删除 /VirtualDir 部分。如果我在部署之前将其删除,那么我需要在部署到虚拟目录时将其重新添加。有什么方法可以将路径设置为相对于虚拟目录而不是网站?
我尝试过使用~,但这也不起作用,如下所示:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="~/ErrorPages/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
【问题讨论】:
-
看来简短的回答是:不,在 IIS7 中设置自定义错误页面时,不能使用相对路径!
-
马丁,我相信你,但你有引文吗?
-
@Michael This link 声明 URL 应该是服务器相对 URL,而不是使用
responseMode="ExecuteURL"时的应用程序相对 URL。
标签: asp.net iis-7 custom-error-handling