I am trying to return 500 Http status code and set a message in Response.Write()
but the browser displays message, "The page cannot be displayed because an internal server error has occurred" and ignores Response.Write()
after setting status code to 500.
[WebMethod]
public void ServiceCheckTest()
{
try
{
HttpContext.Current.Response.Write("Request has been processed");//This works fine
}
catch
{
HttpContext.Current.Response.StatusCode = 500;
//Setting StatusCode = 500 ignores the following message
HttpContext.Current.Response.Write("Request could not be processed. Please try again later");
}
}
Is there a way i can set the http status code to 500 and also set a custom message in Response.Write
.