Use a Custom Content Negotiatior to always return JSON in ASP.NET Web API

The ASP.NET Web API pipeline decides the media formatter to use depending on the request. This complex decision making process occurs during the content negotiation and is handled by the DefaultContentNegotiator. If we need to support only a single format, say JSON, we can replace the default negotiator with …

Read

Inject IPrincipal in ASP.NET Web API Controller

In ASP.NET MVC the current IPrincipal can be automatically made available to action methods by implementing the System.Web.Mvc.IModelBinder interface and returning the current authenticated user from HttpContext.User. We can accomplish the same in Web API using the HttpParameterBinding class. namespace App.Web.Http.Helpers { public …

Read

Download CSV using ASP.NET Web API

The CsvMediaTypeFormatter on Github makes it possible to support text/csv media type to the Web API stack. However, I wanted to rewrite it using the ToCsv() extension method from my earlier post. …

Read