【发布时间】:2011-08-17 20:30:51
【问题描述】:
我在 asp.net 和 C# 中有 Web 应用程序
如果异常发生在此应用程序中的任何位置,我会尝试处理它们。
假设行为应该是如果发生这样的异常
//generate your fictional exception
int x = 1;
int y = 0;
int z = x / y;
它应该在 global.ascx 文件的 app_error 中捕获它并将其重定向到 Default.aspx 页面。我得到了日志记录部分,但重定向不起作用,因为我仍然得到 p>
“/”应用程序中的服务器错误。 页。或者可能是它正在重定向并在中间被杀死..
这就是 global.ascx 中的内容
protected void Application_Error(object sender, EventArgs e)
{
logger.Fatal(this.Server.GetLastError().GetBaseException());
logger.Info("FatalLogger Passed");
//get reference to the source of the exception chain
Exception ex = Server.GetLastError().GetBaseException();
Response.Redirect("~/Default.aspx?error=MessageHere");
}
这在 web.config 的代码中
<authentication mode="Forms">
<forms loginUrl="Login.aspx" defaultUrl="~/Default.aspx" name="GUI" slidingExpiration="true" timeout="30" path="/">
</forms>
</authentication>
任何想法.. 生病;很乐意提供更多信息。
谢谢
好的,我想要这种方法是有原因的,因为每当出现错误时,用户都会退出,我不希望这种情况发生,而是转到默认页面
【问题讨论】:
标签: c# asp.net exception error-handling response