How to use caching in ASP.NET Web API?

Unfortunately, caching is not built into ASP.NET Web API. Check this out to get you on track: http://www.strathweb.com/2012/05/output-caching-in-asp-net-web-api/ An updated resource here: https://github.com/filipw/AspNetWebApi-OutputCache EDIT: As of 2020-02-03, even though this answer is quite old, it’s still valid. Both of the URL’s above lead to the same project, ASP.NET Web API CacheOutput by Filip W

Web API optional parameters

I figured it out. I was using a bad example I found in the past of how to map query string to the method parameters. In case anyone else needs it, in order to have optional parameters in a query string such as: ~/api/products/filter?apc=AA&xpc=BB ~/api/products/filter?sku=7199123 you would use: [Route(“products/filter/{apc?}/{xpc?}/{sku?}”)] public IHttpActionResult Get(string apc = null, … Read more

Is it possible to get a good stack trace with .NET async methods?

First off, stack traces don’t do what most people think they do. They can be useful during debugging, but are not intended for runtime use, particularly on ASP.NET. Also, the stack trace is technically about where the code is returning to, not where the code came from. With simple (synchronous) code, the two are the … Read more

Is there a recommended way to return an image using ASP.NET Web API

You shouldn’t return a System.Drawing.Image, unless you also add a formatter which knows how to convert that into the appropriate bytes doesn’t serialize itself as the image bytes as you’d expect. One possible solution is to return an HttpResponseMessage with the image stored in its content (as shown below). Remember that if you want the … Read more

‘System.Net.Http.HttpContent’ does not contain a definition for ‘ReadAsAsync’ and no extension method

After a long struggle, I found the solution. Solution: Add a reference to System.Net.Http.Formatting.dll. This assembly is also available in the C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies folder. The method ReadAsAsync is an extension method declared in the class HttpContentExtensions, which is in the namespace System.Net.Http in the library System.Net.Http.Formatting. Reflector came to rescue!