追踪未处理的asp.net异常

时间:2022-01-26 03:36:18

We have an asp.net web application and for one of our users, an exception is thrown on a specific page when they click on a button. I have not been able to recreate this issue, but the system is logging an exception when the client gets the exception. The problem is, I don't know where the exception is being generated. When we log an exception, we call the ToString() method on the exception to get the stack trace. It's a parsing error, but I can't tell where it's coming from. Here's the exception as we logged it:

我们有一个asp.net Web应用程序,对于我们的一个用户,当他们点击按钮时会在特定页面上抛出异常。我无法重新创建此问题,但系统在客户端获取异常时记录异常。问题是,我不知道生成异常的位置。当我们记录异常时,我们在异常上调用ToString()方法来获取堆栈跟踪。这是一个解析错误,但我不知道它来自哪里。以下是我们记录的例外情况:

System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo) at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)

System.FormatException:输入字符串的格式不正确。在System.CompumberModel.Int32Converter.FromString(String value,System.Number.ParseInt32(String s,NumberStyles style,NumberFormatInfo info)的System.Number.StringToNumber(String str,NumberStyles options,NumberBuffer&number,NumberFormatInfo info,Boolean parseDecimal)处。 System.ComponentModel.BaseNumberConverter.ConvertFrom上的NumberFormatInfo formatInfo(ITypeDescriptorContext context,CultureInfo culture,Object value)

I assume this is being logged by the following code in the Global.asax

我假设这是由Global.asax中的以下代码记录的

void Application_Error(object sender, EventArgs e) 
    {
        // Code that runs when an unhandled error occurs
        if (Server.GetLastError() != null)
        {
            Exception objErr = Server.GetLastError().GetBaseException();
            objErr.WriteExceptionLog();
        }
    }

However, I don't know where this code is getting called from or how to find out. Any ideas on where I can look or if I need to do something different when I'm logging the exception?

但是,我不知道从哪里调用此代码或如何查找。在我记录异常时,我可以看到哪些想法或者我是否需要做一些不同的事情?

1 个解决方案

#1


Here you go:

干得好:

void Application_Error(object sender, EventArgs e) 
{
    // Code that runs when an unhandled error occurs
    if (Server.GetLastError() != null)
    {
        Exception err = Server.GetLastError().InnerException;

        // handle error here

        Server.ClearError();
    }
}

#1


Here you go:

干得好:

void Application_Error(object sender, EventArgs e) 
{
    // Code that runs when an unhandled error occurs
    if (Server.GetLastError() != null)
    {
        Exception err = Server.GetLastError().InnerException;

        // handle error here

        Server.ClearError();
    }
}