return NotFound () Web Api c #

-1

I need to return a specific message, where it has Get , but it is not working as expected and I tried to implement it separately but it always gives error .

[ResponseType(typeof(pessoa))]
[ActionName("GetCNPJCPF")]
public IHttpActionResult GetCNPJCPF(string cnpj_cpf)
{
     pessoa pessoa = db.pessoa.OfType<pessoa>()
                       .Where(p => p.cpf_cnpj == cnpj_cpf).FirstOrDefault();
     if (pessoa == null)
     {
         return NotFound();
     }
     return Ok(pessoa);
}

If it does not simply find the HTTP 404 error

    
asked by anonymous 02.07.2017 / 02:20

3 answers

1

You can use this:

return Content(HttpStatusCode.BadRequest, "Qualquer objeto");
    
02.07.2017 / 16:56
0

You'll have to create your personalized custom message if you want it to return. Here explains how to do

    
02.07.2017 / 15:13
0

You can try the following:

return NotFound("Sua mensagem aqui");

Output in browser "File not found ..."

    
17.07.2018 / 16:04