开发者

Is it possible to manually send HTTP code 40x to client from ASP.NET Web service method?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜