我正在尝试在asp.net webforms应用程序中使用自定义错误页面,所以我正在做这样的事情(例如404错误):
<httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="ExecuteURL">
<clear />
<error statusCode="404" path="/Pages/Errors/Error404.aspx" responseMode="ExecuteURL" />
</httpErrors>
现在针对这个问题,它似乎工作中途,这意味着当发现未找到页面错误时,它会尝试重定向到我的Error404.aspx页面但导致另一个404错误,因为它无法找到我的自定义页面。这是INCEPTION !!
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Pages/Errors/Error404.aspx
我检查并重新检查了我的路径,页面和错误文件夹存在,Error404.aspx存在,如果我在浏览器中写入路径我可以访问该页面,所以确实存在, 那有什么问题?
答案 0 :(得分:0)
尝试在路径中添加〜:
<error statusCode="404" path="~/Pages/Errors/Error404.aspx" responseMode="ExecuteURL" />
另一个解决方案是使用重定向:
<error statusCode="404" redirect="~/Pages/Errors/Error404.aspx" />