- 在 App_Start 中新建 ModulesHandlerHelper
using System;
using System.Web;
namespace WebFromProject.App_Start
{
public class ModulesHandlerHelper : IHttpModule
{
public void Init(HttpApplication context)
{
context.Error += new EventHandler(context_Error);
}
public void context_Error(object sender, EventArgs e)
{
//此处处理异常
HttpContext ctx = HttpContext.Current;
HttpResponse response = ctx.Response;
HttpRequest request = ctx.Request;
//获取到HttpUnhandledException异常,这个异常包含一个实际出现的异常
Exception ex = ctx.Server.GetLastError();
//实际发生的异常
Exception iex = ex.InnerException;
ctx.Server.ClearError();
}
public void Dispose() { }
}
}
- 在配置文件中增加配置
<system.webServer>
<vali