我正在尝试为我的Web应用程序设置自定义404错误页面.问题是该应用程序将部署到许多不同的环境中.有时它会在虚拟目录中,有时它不会.
我在名为ErrorPages的目录中有错误页面,并设置了我的配置,如下所示:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="/VirtualDir/ErrorPages/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
问题是当我将其部署到网站的根目录时,/VirtualDir需要删除该部分.如果我在部署之前删除它,那么我需要在部署到虚拟目录时重新添加它.有什么办法可以设置相对于虚拟目录而不是网站的路径?
我尝试过使用a ~,但这也不起作用,如下所示:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404"/>
<error statusCode="404" path="~/ErrorPages/404.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)