我不知道为什么当我将代码部署到 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);
}
最佳答案
我遇到了同样的问题并解决了:
HttpContext.Current.ClearError();
Response.Redirect("~/Error.aspx", false);
return;
关于ASP.Net Response.Redirect 在 Application_Error 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4435716/