Base solution for your next web application
Open Closed

Global Exceptions #160


User avatar
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.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

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

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)