ASP.Net Response.Redirect在Application_Error中不起作用?

Leo*_*Leo 14 asp.net redirect

我不知道为什么在将代码部署到IIS7时Response.Redirect无法正常工作?始终显示白色/黄色错误页面而不是我的Errors.aspx.但是当在我的计算机上使用Visual Studio运行调试时,它运行得很好吗?

protected void Application_Error(object sender, EventArgs e)
        {
            ILog log = LogManager.GetLogger(typeof(Global).Name);
            Exception objErr = Server.GetLastError().GetBaseException();
            log.Error(objErr);
            string err = "Error Caught in Application_Error event\n" +
                    "\nError Message:" + objErr.Message.ToString() +
                    "\nStack Trace:" + objErr.StackTrace.ToString();
            EventLog.WriteEntry("Kiosk", err, EventLogEntryType.Error);
            Server.ClearError();
            Response.Redirect("~/Error.aspx", false);
        }
Run Code Online (Sandbox Code Playgroud)

Chr*_*n R 28

我有同样的问题并解决了它:

HttpContext.Current.ClearError();             
Response.Redirect("~/Error.aspx", false);
return;
Run Code Online (Sandbox Code Playgroud)


小智 0

尝试关闭 web.config 中的 CustomError。它将为您提供有关错误详细信息的更具体信息。也许这不是 Response.Redirect 的错误。