If the Accept header contains */*, the Header is ignored unless RespectBrowserAcceptHeader is set to true on MvcOptions. The server is determining what format to return. There isn't any negotiation taking place.The first formatter that can handle the object is used to serialize the response.If no Accept header appears in the request: If no formatter is configured for the requested format, the first formatter that can format the object is used. Tries to find the first formatter that can produce a response.Returns 406 Not Acceptable if MvcOptions.ReturnHttpNotAcceptable is set to true, or.If no formatter is found that can satisfy the client's request, ASP.NET Core: Tries to find a formatter that can produce a response in one of the formats specified.Enumerates the media types in the accept header in preference order.When a request contains an accept header, ASP.NET Core: The Accept headerĬontent negotiation takes place when an Accept header appears in the request. A request for an invalid todo item returns a 204 No Content response. In the preceding code, a request for a valid todo item returns a 200 OK response. The following action method uses the Ok and NotFound helper methods: When a model type is returned, the return type is ObjectResult. The action results helper methods are based on ObjectResult. Built into the status code-specific action results returned from the helper methods.The default format used by ASP.NET Core is JSON. Content negotiationĬontent negotiation occurs when the client specifies an Accept header. For example, when returning different HTTP status codes based on the result of the operation. In the preceding code, the Content-Type returned is text/plain.įor actions with multiple return types, return IActionResult. To return plain text formatted data, use ContentResult and the Content helper: The Accept header is ignored by the preceding code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |