I wrote an simple Web Service in ASP.NET-MVC5 framework. The problem I am faced with is custom status code and response message.
I've tried a lot to find answer here, but solution, that i've found here, didn't work for me.
I use standard try/catch approach to handle my errors. When the catch block recieves an error, it sends a response to the client with a custom error code and JSON file with some additional information about the error/exception.
When I run my application on IIS express it works fine when I send requests from the same server. The same situation presents when I run an application on IIS 7.5 on dev environment and on IIS 8.5 on production environment. But the problem occurs when client try to send request to my application and in case of an error inside the application code, the client receives just the default error page with 400 status code.
I've tried to set CustomError
to different modes, also tried different combination with HttpErrors
node etc.
Doesn't work for me. If CustomError
mode set is to ON
it stopped working for me at all - even for local requests.
That's how I send response to Client:
try
{ } catch () {
Response.StatusCode = 406;
StringBuilder errorMessage = new StringBuilder();
//here I generate json file to be sent with response
string exception = errorMessage.ToString();
return Json(exception, JsonRequestBehavior.AllowGet);
}
Is there any way to make visible response messages for clients' applications not using custom error pages and redirection to them?
P.s. In SO I found a lot of similar question, but there wasn't a direct answer for my question. The main difference between my question and questions i found here, were custom error pages. But for me was anough just send json in response in case of error/exception and make it visible in response content in client side.