我想做一个错误页面,重定向到每当发生错误。自定义错误在asp
这是我的代码:
<customErrors defaultRedirect="Error.aspx" mode="On" />
这是工作的罚款,现在我怎么能得到错误信息太多我的错误页面
例如在:错误 - 指数误差
我想做一个错误页面,重定向到每当发生错误。自定义错误在asp
这是我的代码:
<customErrors defaultRedirect="Error.aspx" mode="On" />
这是工作的罚款,现在我怎么能得到错误信息太多我的错误页面
例如在:错误 - 指数误差
您需要获取发生的最后一个错误(以编程方式)并将其显示在页面中。你可以做这样的(在Error.aspx):
protected void Page_Load(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
lblError.Text= ex.Message;
Server.ClearError();
}
凡lblError
是在你的页面中定义只是用于显示错误消息的目的,一个Label控件。
请参阅here了解更多详情。
也许有用您的伟大文章(从2004年)在*** MSDN *** _https://msdn.microsoft.com/en-us/library/aa479319.aspx_和**构建一个真正有用的ASP.NET异常引擎** http://www.nullskull.com/articles/20030816.asp http://www.codeproject.com/Articles/155810/Back-to-the-Basics -Exception - 管理 - 设计 - Gui_ – Kiquenet
protected override void OnError(EventArgs e)
{
HttpContext ctx = HttpContext.Current;
Exception exception = ctx.Server.GetLastError();
string errorInfo =
"<br>Offending URL: " + ctx.Request.Url.ToString() +
"<br>Source: " + exception.Source +
"<br>Message: " + exception.Message +
"<br>Stack trace: " + exception.StackTrace;
ctx.Response.Write (errorInfo);
ctx.Server.ClearError();
base.OnError (e);
}
我觉得这也是一个类似的一个问题[Server.GetLastError()](http://stackoverflow.com/questions/343014/asp-net-custom- error-page-server-getlasterror-is-null) –