I would like to manually send an HTTP 40x error code to client from a web method in c# asp.net web service.
Specifically I need to send 400 (Bad request) or 401 (Unauthorized).
I was thinking about the flow to look like:
if (a <= 0)
{
//send HTTP Error 400 - Bad request to client
return;
}
Is it possible? 开发者_如何转开发How?
Set the response status code
Response.Clear();
Response.Statuscode = 404; //Your response here
Response.End;
I believe its important to clear the response first in case it is already partially populated
精彩评论