2010-12-14 20 views
13

No sé por qué Response.Redirect no funciona correctamente cuando implemento mi código en IIS7. Siempre se muestra la página de error blanca/amarilla en lugar de mis Errors.aspx. Pero cuando se ejecuta la depuración usando Visual Studio en mi computadora, ¿funciona bien?ASP.Net Response.Redirect no funciona en Application_Error?

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); 
     } 
+0

si adjunta un depurador, se puede entrar en el código a ver si Response.Redirect en realidad se está llamando? –

+0

, depuré usando Visual Studio en mi máquina y funciona bien. Pero cuando se implementa en IIS, ya no se ejecuta – Leo

Respuesta

0

Intenta desactivar CustomError en web.config. Le dará más detalles sobre los detalles del error. Tal vez no es el error de Response.Redirect.

+0

sí, ya lo intenté, sé qué error llevó a este Application_Error a ser llamado y fue registrado correctamente por los códigos de registro anteriores, pero aún no se redirige a Error.aspx :( – Leo

26

que tenían el mismo problema y lo resolvió con:

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

Sí, esto funciona genial. – adinas

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

Para mí trabajó el código de abajo.

HttpContext.Current.Server.ClearError(); 
HttpContext.Current.Response.Redirect("~/ErrorPage.aspx"); 
0
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; 
} 
Cuestiones relacionadas