osx - ASP.NET vnext overriding status code set in controller. Is this a bug? -
i'm building simple webapi in asp.net vnext on mac. i've followed example set in this tutorial i'm having problem response codes set in controller methods being overridden
take method in crudcontroller:
[httppost] public void post([frombody]crudobject crudobject) { var url = url.routeurl("getbyidroute", new {id = 1}, request.scheme, request.host.touricomponent()); context.response.statuscode = 201; context.response.headers["location"] = url; } when curl or hit postman should see 201 created response , location header pointing me url. when run using kestrel location header response code 204 no content.
i assume vnext middleware overriding change status code. right? if so, should overriding status code or bug? if it's correct behaviour, how should redirect?
the behavior of void returning action recently changed not convert 204 status code. however, scenario use createdatroute helper method(this creates createdatrouteresult) sets location header.
[httppost] public void post([frombody]crudobject crudobject) { return createdatroute(routename: "getbyidroute", routevalues: new { id = 1 }, value: null); } is on purpose not want return created object client? if not, modify above code not passing null value parameter.
Comments
Post a Comment