Content Negotiation with Asp.net Core

satish1v
1 min readJul 3, 2018

Asp.net core is a minimalistic framework, and it gives complete control for building an application on your own, and I have found its footprint as minimal as possible.

With that power comes the responsibility too. One of the problems which I recently faced is supporting content negotiation based on the client type. Well in my case it was straightforward to support XML based on the request header.

As I told about Asp.net core content negotiation is not available out of the box, but it is quite easy to achieve the same.To enable this, you need to use the MVC services options to allow the same.

By allowing “RespectBrowserAcceptHeader” to True, we are allowing the asp.net core to provide the response based on the HTTP request header — Accept Headers of the browser. In my case, I need to add a Built-in formatter for XmlSerializer.

To know more about Content negotiation and create your output formatter you can refer the page .

--

--