asp.net - 如何从服务器错误 "the resource cannot be found"中删除版本信息

标签 asp.net .net internal-server-error

浏览页面时,我收到错误:

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: /WebResource.axd

Version Information: Microsoft .NET Framework Version:4.0; ASP.NET Version:4.0.33

错误正如预期的那样,我需要的是一种隐藏/删除版本信息的方法。!?如果有的话...

最佳答案

创建一个您希望用户看到的自定义页面,然后在 web.config 文件中添加类似内容

<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="404.aspx" redirectMode="ResponseRedirect">
<error statusCode="404" redirect="404.aspx" />
 ...
</customErrors>
</system.web>

有3种不同的模式OnOffRemoteOnly

- 指定启用自定义错误。如果未指定 defaultRedirect 属性,用户会看到一般错误。自定义错误会显示给远程客户端和本地主机。

关闭 - 指定禁用自定义错误。详细的 ASP.NET 错误会显示给远程客户端和本地主机。

RemoteOnly - 指定仅向远程客户端显示自定义错误,而向本地主机显示 ASP.NET 错误。这是默认值。

默认为RemoteOnly进一步阅读here 。您也可能想看看这个 answer 如果您想了解 customErrorshttpErrors

之间的区别

关于asp.net - 如何从服务器错误 "the resource cannot be found"中删除版本信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29944480/

相关文章:

c# - 如何在 .NET 中绘制 "on top"的托管控件?

php - 使用 session->set_flashdata 导致 502 Bad gateway 错误

asp.net - 网站/Web 服务部署环境不同/监控?

asp.net - 使用 ASP.NET 表单例份验证进行 IP 检查

javascript - MaterializeCSS - ASP.Net MVC : Checkbox in modal

asp.net - 无法在 Windows Server 2012 上卸载 ASP.NET

c# - 使用 linq C# 将列表转换为嵌套字典

c# - 正确使用迭代 block

php - 使用 php 在 gzopen 中解压缩大型 gzip 文件的缓冲区大小是多少?

python - 使用 JSON 进行 POST 在 Postman 中有效,但在 Python 中无效