在 Windows 7 中,我尝试设置自定义错误页面。一种用于 404,一种用于 500,另一种用于捕获所有其他错误(客户端或服务器端),这些错误是用户在超时或 ASP 编译时出现故障时可能遇到的。
404.htm
500.htm
error.htm
只是非常简单的 html 页面,显示错误,没有像默认值那样的技术性内容。 This post和 this post似乎是在谈论在 ASP 中制作错误页面,而不仅仅是获取 html 文件并将其设置为自定义错误页面。
在 IIS 中,我遇到了不适用于 ASP 的错误页面选择工具
并将此信息输入到编辑错误页面设置
对话框
我输入的完整地址:WebvView\webview_error_pages\error.htm(通过点击侧面的省略号按钮进行浏览后进行选择。(我已缩短了本文中的所有这些地址)。
自定义默认地址有效。但是当我尝试为 404 创建一个错误页面时,如下所示:
并尝试转到不存在的页面,我收到以下简单的错误消息:
The page cannot be displayed because an internal server error has occurred.
不是我的。而不是在我设置自定义 404 之前运行的默认值。
我做错了什么?
谢谢!
编辑
此外,我刚刚更改了 ASP 的某些部分,并收到了运行时错误,而不是我的自定义错误。有什么办法可以阻止用户看到这些可怕的技术页面吗?
编辑 这是其他状态菜单的 xml 代码:
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
<customErrors defaultRedirect="webview_error_pages/error.htm" mode="On">
</customErrors>
</system.web>
<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="502" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="412" subStatusCode="-1" />
<remove statusCode="406" subStatusCode="-1" />
<remove statusCode="405" subStatusCode="-1" />
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
</httpErrors>
</system.webServer>
再次感谢!
最佳答案
您不在 web.config 中执行此操作是否有具体原因?如果您将项目移动到不同的服务器,这将有所帮助,这样您就不必担心手动配置 IIS。另外,在 web.config 中配置它也更容易一些(IMO)。
在 system.web 下的 customErrors 节点中,确保有
<customErrors mode="On" defaultRedirect="~/Error/" >
<error statusCode="404" redirect="~/404Redirect/"/>
</customErrors>
显然,您可以替换您想要的任何重定向页面。
关于asp.net - Windows 7 IIS 中的自定义错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13734518/