I have a series of web services that I need to return an empty response when it encounters an authentication issue. I have the authentication code wrapped in a try block and the catch block looks like this:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.Forbidden;
HttpContext.Current.Response.End();
This code works as expected in my dev environment but once it’s deployed whenever an authentication issue is encountered it returns the default 403 error page markup which isn’t even wrapped in anything it’s just pure HTML markup. The configs are identical between environments. Any one have an idea about what is going on here?
Finally able to get an empty response in the web.config set < httpErrors existingResponse=”PassThrough” > under the system.webserver section.