Open Closed

Global Exceptions #160


0
bvz created

Normally, in an ASP.Net application, I would override Application_Error in Global.asax.cs.

However, when I throw an exception in one of my BaseApplicationService implementations to test:

throw new Exception("TEST!!!");

the code in Global.asax.cs is never hit.

So I now have the following:

public override void Initialize()
        {
            AutoMapperConfig.Configure();
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            EventBus.Default.Register<AbpHandledExceptionData>(x => HandleException(x.Exception));
        }

        private void HandleException(Exception ex)
        {
            EntException exObj = ex.GetHttpExceptionObject();
        }

This works. However, I need the HttpRequest object, becuase I need to log Headers and Form values and UserAgents and all kinds of other goodies from the HttpRequest object. This is easy in the Global.asax.cs Application_Error, because HttpRequest is in scope there.

So I need to:

  1. Access the Request object where the exception was raised.
  2. Make sure exceptions handled by Asp.Net boilerplate internals still reach Global.asax.cs.

Please advise. Thank you for your time and effort.


1 Answer(s)
  • 0
    hikalkan created

    You may try to get HttpContext.Current.Request in HandleException method.