ASP.Net Response.Redirect не работает в Application_Error?

Я не знаю, почему Response.Redirect не работает должным образом при развертывании моего кода в IIS7? Страница ошибок белого/желтого цвета всегда отображается вместо моего 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);
        }

Ответы

Ответ 1

У меня была та же проблема, и я решил:

HttpContext.Current.ClearError();             
Response.Redirect("~/Error.aspx", false);
return;

Ответ 2

Для меня работает код ниже.

HttpContext.Current.Server.ClearError();
HttpContext.Current.Response.Redirect("~/ErrorPage.aspx");

Ответ 3

Попробуйте отключить функцию CustomError в web.config. Это даст вам более подробную информацию об ошибках. Возможно, это не ошибка от Response.Redirect.

Ответ 4

HttpContext.Current.Server.ClearError();
HttpContext.Current.ClearError();
====================================================================
Redirect to NEW VIRTUAL! directory (Error)
HttpContext.Current.Response.Redirect([http://localhost:8990/Error/ErrorPageServer.aspx]);

Ответ 5

protected void Application_Error(object sender, EventArgs e)
{            
     Exception objErr = Server.GetLastError().InnerException;
    //Logging.WriteToErrorLog("Error Caught in Application_Error event", objErr);
   HttpContext.Current.Server.ClearError();
   HttpContext.Current.Application.Add("test", objErr);
   HttpContext.Current.Response.Redirect("~/Home/Index");
   return;
}