C# Global.asax-应用程序错误-如何获取页面数据?
我有以下代码:C# Global.asax-应用程序错误-如何获取页面数据?,c#,asp.net,global-asax,C#,Asp.net,Global Asax,我有以下代码: using System.Configuration; void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError().GetBaseException(); string ErrorMessage = ex.Message; string StackTrace = ex.StackTrace; string ExceptionT
using System.Configuration;
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
string ErrorMessage = ex.Message;
string StackTrace = ex.StackTrace;
string ExceptionType = ex.GetType().FullName;
string UserId = Getloggedinuser();
string WebErrorSendEmail =
ConfigurationManager.AppSettings["WebErrorSendEmail"];
// save the exception in DB
LogStuffInDbAndSendEmailFromDb();
}
这是(大部分)我的代码。
在一小部分案例中,我没有得到足够的信息。我不知道异常来自哪个页面
如何获取与异常源页面相关的任何类型的信息
下面是最短消息的示例:
Base-64字符数组的长度无效
at System.Convert.FromBase64String(字符串s)at
System.Web.UI.ObjectStateFormatter
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(字符串
(数据状态)在
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter格式化程序,
字符串序列化(数据状态)位于
System.Web.UI.HiddenFieldPageStatePersister.Load()
您可以按如下方式获取当前请求的URL和页面:
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
if (HttpContext.Current != null)
{
var url = HttpContext.Current.Request.Url;
var page = HttpContext.Current.Handler as System.Web.UI.Page;
}
}