Category Archives: c#

April, 2014

Opt in and opt out from ASP.NET Web API Help Page

The autogenerated ASP.NET Web API help page is an extremely useful tool for documenting your Web API. It can not only present information about the routes, but also show sample requests and responses in all of supported media type formats, and even display information for DataAnnotations.

However, more often than not, you don’t want all endpoints to be visible in the help page. Let’s have a look at how you can opt in and opt out from the ASP.NET Web API Help Page with your resources.

Continue reading

March, 2014

ASP.NET Web API exception logging with Raygun.io

Jon Galloway recently wrote a monster 4-part series covering the new features of MVC 5.1 and Web API 2.1 releases. One thing he mentioned was the new IExceptionLogger for Web API, and he called out the community to provide some example implementations of it.

Therefore, let’s have a look at how you’d approach that – with a sample of logging Exceptions to the excellent Raygun service from Mindscape.

Continue reading

Per request tracing in ASP.NET Web API

Web API allows you to plug in extensive logging mechanism through the ITraceWriter service. This will log all important events in the pipeline – such as selection of the controller, action, parameter binding and so on – all of which are extremely important in debugging all kinds of issues.

However, any existing instance of an ITraceWriter would log all of the information aside – into a log file, trace, database. But what if you wanted all the trace information produced while the given request was being processed, to be returned together with the server response?

Let’s have a look.

Continue reading

February, 2014

Running the OWIN pipeline in the new .NET Azure Mobile Services

OWIN in ZUMO!

Yesterday, a preview of the .NET Azure Mobile Services has been released. Despite the fact that I’d rather see a scripted C# support :) – I am still very excited about this new .NET support, as ZUMO is one of my favorite Azure offerings.

The whole thing is in preview right now and runs on Web API (version 5.1 at the moment, so not the latest) but the team has made several very smart decisions, which I am sure the community will welcome with open arms. One of them is the ability to plug in your OWIN pipeline!

Continue reading

Getting started with OData v4 in ASP.NET Web API

Because v4 is almost here!

Since yesterday, the ASP.NET Web stack nightly feed contains the packages supporting OData v4. The package is called Microsoft.AspNet.OData and has a working version 5.2.0 – so I’m guessing this is intended to ship with Web API 2.

It relies on the latest beta of Microsoft.OData.Core. OData v4 is a massive changed compared to v3 – you can read about all of them here.

Continue reading

January, 2014

Return types, action parameters and data annotations now available in Web API 2.1 Help Page

On Friday Microsoft released a 2.1 version of Web API (along with MVC 5.1 and Web Pages 3.1). The release announcement was made yesterday and can be read here – but pretty much all of the new features have already been discussed on this blog, when we dissected the 2.1 RC released last month.

One thing I wanted to highlight today though, are the changes to the Help Page, and its new capabilities to document return types, action parameters and data annotations on your models/DTOs.

Continue reading

December, 2013

OWIN/Katana in-memory integration testing

Because in memory testing is extremely efficient!

A while ago we looked at testing the ASP.NET Web API pipeline using its in-memory hosting capabilities.

The advantages of such approach to end-to-end testing are unquestionable.

Now, with the emergence of OWIN as the primary hosting option for a wide array of web frameworks, it makes sense to explore how you could to the same, except in the OWIN (or rather Katana, since all the things shown here are Katana specific) context – so not just against Web API, but against any framework of your choice (running on top of OWIN & Katana).

Continue reading

ASP.NET Web API 2.1 RC is out – what’s new?

Fresh out of the oven

It seems that only yesterday we were blogging about new features in Web API 2 and discussing what’s coming up next for Web API at the MVP Summit.

Meanwhile, the ASP.NET team kept it’s frantic work pace and already before Christmas dropped on Nuget a 2.1 RC of Web API (as well as new MVC and Web Pages).

While in the open source mode of operation (public commits, nightly builds) this is that big of a news, it is still a very nice piece of news. Let’s look at what’s new.

Continue reading

Easier Redis development with scriptcs and ServiceStack.Redis powered C# REPL

Work with Redis like a pro

In my current project I am working a lot with Redis on the back end. What I have found extremely useful is the ability to work with Redis directly from its REPL (redis-cli), to instantly check or reset the objects stored there.

However, working in the C# environment, the basic redis-cli is definitely not enough to facilitate productive development.

Enter scriptcs.

Continue reading

November, 2013

Asynchronous action filters in ASP.NET Web API

It is rather to common to use filters in Web API to perform common tasks around your actions in an AOP (aspect oriented programming) way.

To create a filter you simply inherit from an abstract ActionFilterAttribute class and override the relevant method:

This is all nice and simple, but what if the operation you need to perform, should by asynchronous? Surely async void is a terrible idea.

Continue reading