Request.CreateResponse vs returning POCOs in ASP.NET Web API

前端 未结 2 646
孤独总比滥情好
孤独总比滥情好 2021-01-16 07:21

I see a lot of samples on the web for ASP.NET Web API that use Request.CreateResponse to generate responses. If you create a new Web API project in Visual Studi

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-16 08:15

    Request.CreateResponse can generate other http message, ex.404,500. If just return,the http message will be 200 OK.

    In my code, if get need authorized, I will return like this:

    throw new HttpResponseException(HttpStatusCode.Unauthorized);
    

    write this,you unnecessary change the return value.

提交回复
热议问题