Can I manually send 40x HTTP code to a client from an ASP.NET web service method?

I would like to manually send the HTTP 40x error code to the client from the web method in the C # asp.net web service .

In particular, I need to send 400 (invalid request) or 401 (unauthorized).

I thought about the flow as follows:

if (a <= 0) { //send HTTP Error 400 - Bad request to client return; } 

Is it possible? How?

+4
source share
1 answer

Set response status code

 Response.Clear(); Response.Statuscode = 404; //Your response here Response.End; 

I believe that it is important to clear the answer first if it is already partially populated.

+5
source

Source: https://habr.com/ru/post/1335443/


All Articles