Base solution for your next web application
Open Closed

Add Http Status codes in DynamicAPI and/or AbpApiController #1758


User avatar
0
ramanan created

I am trying to pass custom Http Status codes in the response headers, when using Asp.Net boiler plate Dynamic API and web api written by inheriting AbpApiController.

The following are the two ways I tried, but failed: a) In the AppService, I used

public async Task<HttpResponseMessage> GetData() 
{
    HttpResponseMessage response=new HttpResponseMessage();
    response.Headers.Add("Status", "201");
    return response;
}

b) My another approach was to write an ApiController which inherited AbpApiController. And in that, I wrote

public IHttpActionResult GetData()
{
     var data=null;
     return NotFoundResult(data);
 }

Both of these approaches failed. How do we implement this?

Thanks in advance :-)


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    You should not (and can not) write web specific code into your application layer. if you need it, you should write regular web api controllers (derived from AbpApiController as you do) and it should be like that:

    public IHttpActionResult GetData()
    {
        //...
        return NotFound();
    }
    

    BTW, "var data=null;" is not a valid C# statement.