How to add JSON Patch support to ASP.NET Web API

In this post we’ll look at how to introduce support for the JSON Patch content type (RFC 6902) to ASP.NET Web API. There’s an unlimited number of ways to introduce HTTP Patch support into your API as there’s no single specification on how to represent the set of changes to make to a resource. The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI. [Read More]

Dependency injection for ASP.NET Web API action filters in 3 easy steps

This post looks at performing dependency injection on a WebAPI ActionFilter using Unity. Since we’re looking at WebAPI we’ll be looking at classes which implement the ActionFilterAttribute base class under the System.Web.Http.Filters namespace. We will be using the Unity Application Block (Unity) to do most of the heavy lifting. It’s a lightweight dependency injection container created by the Microsoft Patterns and Practices team. 1) The ActionFilter First you need to implement your shiny new ActionFilter that requires a dependency to be injected. [Read More]

Automatically marking required labels in ASP.NET MVC

A common requirement with any sort of form is marking the required fields. A common convention is to append an asterisk (*) to the label of all required fields. Normally I’d manually add the asterisk directly in the HTML, or add the [display] attribute to the model so that the @Html.LabelFor picks it up automatically. public class SomeModel { [Required, Display(Name = "Email*")] public string Email { get; set; } public string Subject { get; set; } } I prefer to get the HTML Helpers to add it as I’m less likely to forget to mark any of the fields. [Read More]

Implementing XML-RPC services in ASP.NET MVC

Earlier this month I moved my blog to a brand new design to improve the readability of the posts. The admin section was also in desperate need of an upgrade but it would have taken a lot of development effort to create something decent. I ended up just nuking it in favour of using a desktop blogging client. To support various 3rd party blogging clients we just need to implement the MetaWeblog API. [Read More]

Configuring a Live Connect application to use the new Microsoft Account permission page

When I first configured the new version of ConceptHQ Accounts to federate with Microsoft account using OAuth I used these two endpoints which I picked out of a sample. https://oauth.live.com/token https://oauth.live.com/authorize It resulted in a slightly jarring user experience as we switch from the new look sign in page to the old style permissions page. However, by switching to the new OAuth 2.0 endpoints https://login.live.com/oauth20_token.srf https://login.live.com/oauth20_authorize.srf We get a much smoother experience as the styles between the sign in and permissions page remain the same. [Read More]

ASP.NET MVC and TempData

TempData initially seemed kind of magical and uber useful! Represents a set of data that persists only from one request to the next. Today I almost used it in a multi-instance Azure set up which didn’t use session state and so didn’t have a central session store. Whoops. Why was that bad? By default TempData is stored in session state, which means if the redirected request didn’t hit the same instance then it would look like TempData was simply not set. [Read More]

Error handling in ASP.NET MVC Part 2: Our implementation

In part 1 of this series we looked at the options available to us to handle errors in ASP.NET MVC. In this part of the series we will look at our implementation. Our implementation consists of two components. A custom exception filter that’s registered globally to handle any exceptions while processing filters, actions, and views. The Application_Error method in Global.aspx to catch any other errors generated while ASP.NET processes the request. [Read More]

Error handling in ASP.NET MVC Part 1: Our options

This blog and most of the web applications we build over at solve.solutions are based on Microsoft’s ASP.NET MVC framework. We wanted a standardised way to approach error handling across our web applications. We had a couple of requirements Super easy to implement Covers the entire ASP.NET request pipeline See friendly error messages in production and see stack traces in development Respects HTTP status codes - we do not want the site returning a 302 redirect on error to redirect to an error page Able to log exceptions This is the first post in a two part series, in this part we will look at the options available to us in ASP. [Read More]

The problem with absolute token expiration in Windows Identity Foundation (WIF)

The problem While developing CronHQ we initially had problems with our Facebook integration. Rule #6 of the Facebook guidelines require us to provide an explicit logout link. 6. Your website must offer an explicit “Log Out” option that also logs the user out of Facebook However Azure ACS 2.0 doesn’t really support single sign out making the requirement a little harder to meet. This isn’t just Facebook being difficult, it makes sense to enforce this on every identity provider that we federate with. [Read More]

Simple pluralisation in ASP.NET MVC

Your software application is like an iceberg. Your users only see a small fraction of the application, the parts that they interact with. Your application can be a mess under the covers but as long as you have a beautiful, quick interface that’s super usable, your uses will think your app is designed really well. If you don’t bother with correct pluralisation your users will be less likely to appreciate the care you put into the rest of your application. [Read More]