When using the ASP.NET Web API, how can I check the content types requested, whether the application / XML or Is the app / jsn? I know about the content conversation in ASP.Net Web API, but it is not working with me because I get data from the database in XML format. So if I can check the requested content type, then the XML can be converted to Jasonson when the request content type XML otherwise returns to the XML otherwise.
Thanks in advance
Would you like to see if they want JSON That you want to inspect the accept headers vs. XML To do this, you must inspect the reference headers of the reference. There are at least two ways to do this. Option # 1 - Implement within the API control system Inspect what to do inside your API method to do this: Option # 2 - Use an ActionFilterAttribute < / P> With this, you can also see what the customers want to get back. Public class HttpUserContextFilterAttribute: ActionFilterAttribute {Public Override Zero OnActionExecuting (HttpActionContext actionContext) {// This is where you can see the example of header // Check the operation. Reference. request. Header. Accept
this.ControllerContext.Request.Headers.Accept
Comments
Post a Comment