C# ASP.NET错误处理-在Global.asax中未检测到正确的错误类型

C# ASP.NET错误处理-在Global.asax中未检测到正确的错误类型,c#,asp.net,exception,types,exception-handling,C#,Asp.net,Exception,Types,Exception Handling,我定义了一些自定义错误类,每个类都有自己的功能(未显示): 例外。cs public abstract class MyAppException : Exception { //... } public class ValidationException : MyAppException { //... } public class AccessDeniedException : MyAppException { //... } protected void Page_Load(o

我定义了一些自定义错误类,每个类都有自己的功能(未显示):

例外。cs

public abstract class MyAppException : Exception {
  //...
}
public class ValidationException : MyAppException {
  //...
}
public class AccessDeniedException : MyAppException {
  //...
}
protected void Page_Load(object sender, EventArgs e)
{
  throw new AccessDeniedException();
}
protected void Application_Error(object sender, EventArgs e) {
  var exc = Server.GetLastError();
  if (exc is MyAppException) ((MyAppException)exc).Log();
}
现在,在空白页的代码隐藏中,我有:

test.aspx.cs

public abstract class MyAppException : Exception {
  //...
}
public class ValidationException : MyAppException {
  //...
}
public class AccessDeniedException : MyAppException {
  //...
}
protected void Page_Load(object sender, EventArgs e)
{
  throw new AccessDeniedException();
}
protected void Application_Error(object sender, EventArgs e) {
  var exc = Server.GetLastError();
  if (exc is MyAppException) ((MyAppException)exc).Log();
}
我的目的是在应用程序级别了解这一点:

Global.asax.cs

public abstract class MyAppException : Exception {
  //...
}
public class ValidationException : MyAppException {
  //...
}
public class AccessDeniedException : MyAppException {
  //...
}
protected void Page_Load(object sender, EventArgs e)
{
  throw new AccessDeniedException();
}
protected void Application_Error(object sender, EventArgs e) {
  var exc = Server.GetLastError();
  if (exc is MyAppException) ((MyAppException)exc).Log();
}
但是通过添加断点,我发现
exc is MyAppException
的计算结果为
false


我哪里出错了?

尝试内部异常:

if (exc.InnerException is MyAppException)
System.Web.UI.Page.HandleError
方法将实际异常包装到
HttpUnhandledException