Webapi formdata upload (to DB) with extra parameters

Expanding on gooid’s answer, I encapsulated the FormData extraction into the provider because I was having issues with it being quoted. This just provided a better implementation in my opinion. public class MultipartFormDataMemoryStreamProvider : MultipartMemoryStreamProvider { private readonly Collection<bool> _isFormData = new Collection<bool>(); private readonly NameValueCollection _formData = new NameValueCollection(StringComparer.OrdinalIgnoreCase); private readonly Dictionary<string, Stream> _fileStreams … Read more

Post byte array to Web API server using HttpClient

WebAPI v2.1 and beyond supports BSON (Binary JSON) out of the box, and even has a MediaTypeFormatter included for it. This means you can post your entire message in binary format. If you want to use it, you’ll need to set it in WebApiConfig: public static class WebApiConfig { public static void Register(HttpConfiguration config) { … Read more

How to use Newtonsoft.Json as default in Asp.net Core Web Api?

In .NET Core 3.0+ include the NuGet package Microsoft.AspNetCore.Mvc.NewtonsoftJson and then replace services.AddControllers(); in ConfigureServices with services.AddControllers().AddNewtonsoftJson(); This is a pre-release NuGet package in .NET Core 3.0 but a full release package in .NET Core 3.1. I came across this myself, but I’ve found that the same answer with some additional info is in this … Read more

How to use a client certificate to authenticate and authorize in a Web API

Tracing helped me find what the problem was (Thank you Fabian for that suggestion). I found with further testing that I could get the client certificate to work on another server (Windows Server 2012). I was testing this on my development machine (Window 7) so I could debug this process. So by comparing the trace … Read more

How can Xml Documentation for Web Api include documentation from beyond the main project?

There is no built-in way to achieve this. However, it requires only a few steps: Enable XML documentation for your subproject (from project properties / build) like you have for your Web API project. Except this time, route it directly to XmlDocument.xml so that it gets generated in your project’s root folder. Modify your Web … Read more

Constructor Dependency Injection WebApi Attributes

Yes, it is possible. You (like most people) are being thrown by Microsoft’s marketing of Action Filter Attributes, which are conveniently put into a single class, but not at all DI-friendly. The solution is to break the Action Filter Attribute into 2 parts as demonstrated in this post: An attribute that contains no behavior to … Read more