You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何排查System.Web.HttpUnhandledException异常及访问InnerException

解决ASP.NET部署后白屏及异常InnerException查看问题

当前日志已暴露InnerException

你提供的日志里其实已经显示了HttpUnhandledException的InnerException:

---> System.Reflection.TargetParameterCountException: Parameter count mismatch.

这个异常出现在Core.Web.Controls.SmartView.SaveChildViewState()方法中,是通过反射调用方法时传入的参数数量和目标方法要求不匹配导致的。

无源码情况下获取更详细InnerException的方法

如果需要查看更深层级的InnerException或更完整的异常信息,可通过以下操作实现:

1. 启用详细错误页面

修改应用根目录下的Web.config,找到<customErrors>节点(没有则添加),将其设置为:

<configuration>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
</configuration>

保存后重启IIS应用池,在服务器本地访问应用页面,就能看到包含完整InnerException的详细错误信息。

2. 检查Windows事件查看器

打开服务器的事件查看器,依次展开Windows日志 > 应用程序,查找来源为ASP.NET或w3wp.exe的错误事件,部分场景下会记录更完整的异常堆栈,包含所有层级的InnerException。

3. 临时添加全局异常捕获

如果应用没有Global.asax文件,可在应用根目录新建一个,添加以下代码捕获全局异常并写入日志文件:

<%@ Application Language="C#" %>
<script runat="server">
    void Application_Error(object sender, EventArgs e)
    {
        Exception ex = Server.GetLastError();
        string logPath = Server.MapPath("~/App_Data/error.log");
        using (StreamWriter sw = File.AppendText(logPath))
        {
            sw.WriteLine($"[{DateTime.Now}] 异常信息:");
            while (ex != null)
            {
                sw.WriteLine($"- {ex.GetType().Name}: {ex.Message}");
                sw.WriteLine($"堆栈:\n{ex.StackTrace}\n");
                ex = ex.InnerException;
            }
        }
        Server.ClearError();
    }
</script>

保存后重启应用池,再次触发错误后,查看App_Data/error.log文件,就能看到所有层级的InnerException详情。

4. 调整日志配置(如果应用有日志框架)

如果应用使用了log4net、NLog等日志框架,可修改其配置文件,将日志级别调整为Debug或Error的详细输出模式,确保日志记录所有异常的InnerException信息。

内容的提问来源于stack exchange,提问作者Maaverick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 18:45:58