Reputation: 2661
We have our web site and web services hosted on separate domains. To enable CORS, I've setup every request to send the Access-Control-Allow-Origin header with the appropriate domain via the Application_BeginRequest header in the global asax.
This works most of the time, except when an error occurs. When an error occurs, we get the standard ASP.Net Yellow Page of Death with the stack trace. The problem is, the Access-Control-Allow-Origin header I appended to response gets removed; and when debugging the site, we can't see the error due to browser security restrictions.
Is there anyway to send a custom header with the the ASP.Net YPOD? I tried adding the header in the Application_Error event handler, but the CORS header still gets lost.
I know I could just bypass the YPOD totally, catch any exception that happens in our web services, and spit out a custom error response, but I'm trying to avoid that if possible.
Any constructive input is greatly appreciated.
Upvotes: 1
Views: 884
Reputation: 2661
Figured it out. The trick was to handle the Application_EndRequest event in global.asax.cs and then append the CORS header there.
Upvotes: 1