ASP.NET / Mono MVC4 Web API v.1 application.
API controllers are using Forms authorication and are decorated with standard [Authorize] attribute. If authorization fails, standard api error message
<Error>
<Message>Authorization has been denied for this request.</Message>
</Error>
occurs. How to itercept this error for sriting to log file . Error message returned to caller shoudl remain the same. how to add additional code to this which can wrote this error message with whole http request headers and body to log file ?
I added code from question
How do I log ALL exceptions globally for a C# MVC4 WebAPI app?
and from
How to catch undefined api method calls in ASP.NET MVC4 Web API
but athorization error is not catched.
How to catch all errors ?
Update
code needs to run in Windows 2003 server. I tried code from answer but got compile errors
Predefined type 'System.Runtime.CompilerServices.IAsyncStateMachine' is not defined or imported
Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?
Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?
How to run int in W2003 server ?