You can do this by setting the Produces("ResultType") attribute to the controller action. For instance:
[Produces("application/xml")] public Object Index() { return new { Id = 100 }; }
formatter for this type of result will be used to convert the object , regardless of the Accept Header .
But for the type of response, you must register the formatter . Therefore, if you want to use "text/x-vcard" , you will need to create a formatter for it.
To do this, you need to create a class that implements IOutputFormatter and register it in Startup.cs in the ConfigureServices() method, for example:
services.Configure<MvcOptions>(options => { options.OutputFormatters.Add(new VCardFormatter()); });
Here are some additional resources that can help you:
Content Consolidation in MVC 6
Formatting in ASP.NET MVC 6
source share