0

我正在尝试在 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 错误。这是开始!!

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

我检查并重新检查了我的路径,Pages和Errors文件夹存在,Error404.aspx存在,如果我在浏览器中写入路径我可以访问该页面,所以确实存在,那么问题是什么?

4

1 回答 1

0

尝试在路径中添加~:

<error statusCode="404" path="~/Pages/Errors/Error404.aspx" responseMode="ExecuteURL" />

另一种解决方案是使用重定向:

<error statusCode="404" redirect="~/Pages/Errors/Error404.aspx" />
于 2013-08-23T23:56:47.590 回答