ASP.NET Core v2 (2015) MVC : How to get raw JSON bound to a string without a type?

The cleanest option I’ve found is adding your own simple InputFormatter: public class RawJsonBodyInputFormatter : InputFormatter { public RawJsonBodyInputFormatter() { this.SupportedMediaTypes.Add(“application/json”); } public override async Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context) { var request = context.HttpContext.Request; using (var reader = new StreamReader(request.Body)) { var content = await reader.ReadToEndAsync(); return await InputFormatterResult.SuccessAsync(content); } } protected override bool CanReadType(Type type) … Read more

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

How to use Newtonsoft.Json as default in 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