我有一个在 IIS 6.0 上运行的 ASP.NET 4.0 MVC Web 应用程序,其 webconfig 自定义错误部分为:
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="/Home/Error">
<error statusCode="403" redirect="/Home/Error"/>
<error statusCode="404" redirect="/Home/Error"/>
</customErrors>
和一个如下所示的 error.aspx 页面:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.HandleErrorInfo>" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Threading" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Error
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Error Processing your request.</h2>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Scripts" runat="server">
<script runat="server">
void Page_Load() {
byte[] delay = new byte[1];
RandomNumberGenerator prng = new RNGCryptoServiceProvider();
prng.GetBytes(delay);
Thread.Sleep((int)delay[0]);
IDisposable disposable = prng as IDisposable;
if (disposable != null) { disposable.Dispose(); }
}
</script>
</asp:Content>
每当我在 webconfig 自定义错误部分包含上述“redirectMode="ResponseRewrite"”时,重定向到我的自定义错误页面就不再起作用,并且我收到页面错误““/”应用程序中的服务器错误 - 资源无法成立”。事实上, Controller 的操作也被忽略。当我采取这种设置时,我们的一切都会按预期进行。我正在尝试采用 Scott Gu 针对此处列出的 Asp.net 安全漏洞的解决方法:http://weblogs.asp.net/scottgu/archive/2010/09/18/important-asp-net-security-vulnerability.aspx
任何帮助将不胜感激。 谢谢, 比利
最佳答案
当我尝试在 MVC 应用程序上实现此功能时遇到的问题是我们使用的 MVC URL 需要路由作为默认重定向。不幸的是,由于 server.transfer 是使用 ResponseRewrite 重定向模式执行的,因此这不起作用。相反,我必须使错误 url 直接指向 aspx 文件。此外,您不再有权访问 session ,这是人们在使用 ResponseRewrite 重定向模式时遇到的另一个常见问题。
关于security - MVC - 设置重定向模式时 CustomErrors 不起作用 =“ResponseRewrite”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3779581/