ASP.Net Response.Redirect not working in Application_Error?
I don't know why the Response.Redirect not working properly when I deploy my code to IIS7? The white/yellow error page always get displayed instead of my Errors.aspx. But when debug running using Visual Studio on my computer, it runs just fine?
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 Tra开发者_如何学Cce:" + objErr.StackTrace.ToString();
EventLog.WriteEntry("Kiosk", err, EventLogEntryType.Error);
Server.ClearError();
Response.Redirect("~/Error.aspx", false);
}
I had the same problem and solved it with:
HttpContext.Current.ClearError();
Response.Redirect("~/Error.aspx", false);
return;
HttpContext.Current.Server.ClearError();
HttpContext.Current.ClearError();
====================================================================
Redirect to NEW VIRTUAL! directory (Error)
HttpContext.Current.Response.Redirect([http://localhost:8990/Error/ErrorPageServer.aspx]);
For me the below code worked.
HttpContext.Current.Server.ClearError();
HttpContext.Current.Response.Redirect("~/ErrorPage.aspx");
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;
}
Try to turn off the CustomError in web.config. It will give you more specific about the error details. Maybe it doesn't the error from Response.Redirect.
精彩评论