Best and Cheap Cloud ASP.NET Hosting – Easy to Improve ASP.NET Web API Performance

ASP.NET is a web application framework developed and marketed by Microsoft to allow programmers to build dynamic web sites. If you use a full featured programming language such as C# or VB.NET to build web applications easily. ASP.NET Web API is a great piece of technology. Writing Web API is so easy that many developers don’t take the time to structure their applications for great performance. In this article, we will cover 8 techniques for improving ASP.NET Web API performance.
Best and Cheap Cloud ASP.NET Hosting – Easy to Improve ASP.NET Web API Performance

Use fastest JSON serializer

JSON serialization can affect overall performance of ASP.NET Web API significantly. A year and a half we have switched from JSON.NET serializer on one of our project toServiceStack.Text.
We have measured around 20% performance improvement on our Web API responses. We highly recommend that you try out this serializer.

Manual JSON serialize from DataReader

We have used this method on our production project and gain performance benefits.
Instead reading values from DataReader and populating objects and after that reading again values from those objects and producing JSON using some JSON Serializer, you can manually create JSON string from DataReader and avoid unnecessary creation of objects.
You produce JSON using StringBuilder and in the end you return StringContent as the content of your response in WebAPI
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(jsonResult, Encoding.UTF8, “application/json”);
return response;

Use other formats if possible (protocol buffer, message pack)

If you can use other formats like Protocol Buffers or MessagePack in your project instead of JSON do it. You will get huge performance benefits not only because Protocol Buffers serializer is faster, but because format is smaller than JSON which will result in smaller and faster responses.

Implement compression

Use GZIP or Deflate compression on your ASP.NET Web API. Compression is an easy and effective way to reduce the size of packages and increase the speed.

Use caching

If it makes sense, use output caching on your Web API methods. For example, if a lot of users accessing same response that will change maybe once a day.

Use classic ADO.NET if possible

Hand coded ADO.NET is still the fastest way to get data from database. If the performance of Web API is really important for you, don’t use ORMs. You can see one of the latest performance comparison of popular ORMs. The Dapper and the hand-written fetch code are very fast, as expected; all ORMs are slower than those three. LLBLGen with resultset caching is very fast, but it fetches the resultset once and then re-materializes the objects from memory.

Implement async on methods of Web API

Using asynchronous Web API services can increase the number of concurrent HTTP requests Web API can handle. Implementation is simple. The operation is simply marked with the sync keyword and the return type is changed to Task.
public async Task OperationAsync() 
    await Task.Delay(2000); 

Return Multiple Resultsets and combined results

Reduce number of round-trips not only to database but to Web API as well. You should use multiple resultsets functionality whenever is possible.
This means you can extract multiple resultsets from DataReader like in the example bellow:
// read the first resultset
var reader = command.ExecuteReader();
// read the data from that resultset
while (reader.Read())
    suppliers.Add(PopulateSupplierFromIDataReader( reader ));
// read the next resultset
// read the data from that second resultset
while (reader.Read())
    products.Add(PopulateProductFromIDataReader( reader ));
Return as many objects you can in one Web API response. Try combining objects into one aggregate object like this:
public class AggregateResult
     public long MaxId { get; set; }
     public List<Folder> Folders{ get; set; }
     public List<User>  Users{ get; set; }

This way you will reduce the number of HTTP requests to your Web API.

Best and Recommended ASP.NET 4.5 Hosting Solution

Are you looking for ASP.NET hosting? Look no further! You have found the answer. is your ASP.NET 4.5 hosting home! They understand that as .NET developer, you need to find good .NET hosting that provide reliable and cheap .NET hosting. supports the latest .NET framework, .NET 4.5, as well as past frameworks like .NET 4.NET 3.5, and .NET 2.0. All of their.NET hosting comes with FREE Trial Hosting. If the service does not meet your expectations, simply cancel before the end of the free trial period. No Risk!! Why wait longer? is Microsoft No #1 Recommended Windows and ASP.NET Spotlight Hosting Partner in United States. Microsoft presents this award to for the ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2012, .NET 4.5.2/ASP.NET 4.5.1, ASP.NET MVC 6.0/5.2, Silverlight 5 and Visual Studio Lightswitch. Click here for more information

Rate this post