2010-12-14 42 views
13

Tôi không biết tại sao Response.Redirect không hoạt động đúng khi tôi triển khai mã của mình lên IIS7? Trang lỗi trắng/vàng luôn được hiển thị thay vì tệp Errors.aspx của tôi. Nhưng khi gỡ lỗi chạy bằng cách sử dụng Visual Studio trên máy tính của tôi, nó chạy tốt?ASP.Net Response.Redirect không hoạt động trong 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

nếu bạn đính kèm một debugger, bạn có thể đột nhập vào mã tại xem Response.Redirect được thực sự được gọi là? –

+0

tốt, tôi gỡ lỗi bằng cách sử dụng Visual Studio trên máy tính của tôi và nó chạy tốt. Nhưng khi triển khai vào IIS, nó không chạy nữa – Leo

Trả lời

0

Hãy thử tắt CustomError trong web.config. Nó sẽ cung cấp cho bạn cụ thể hơn về các chi tiết lỗi. Có lẽ nó không phải là lỗi từ Response.Redirect.

+0

vâng tôi đã thử điều đó, tôi biết lỗi nào dẫn đến Application_Error này được gọi và nó đã được ghi lại đúng bởi các mã đăng nhập ở trên nhưng nó vẫn không chuyển hướng tới Error.aspx :( – Leo

26

tôi đã cùng một vấn đề và giải quyết nó với:

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

Yup, công trình này tuyệt vời. – 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

Đối với tôi vào mã bên dưới làm việc.

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; 
} 
Các vấn đề liên quan