Tjek om bilen er blevet spolet

DR1 viste i programmet Bag Facaden hvordan nogle brugtbilsforhandlere snyder med bilernes kilometertæller. De “spoler” tælleren flere tusinde kilometer tilbage. I flere tilfælde kan man finde frem til denne svindel gennem Trafikstyrelsens selvbetjeningswebsite ved at indtaste bilens registreringsnummer eller stelnummer.

Jeg har implementeret et lille website der gør brug af Trafikstyrelsens data, og nemt og hurtigt kan fortælle om en bil er blevet spolet. Du skal blot indtaste registreringsnummer eller stelnummer samt nuværende kilometer antal.

Prøv selv på http://erbilenspolet.azurewebsites.net/.

Screenshot af "Er bilen spolet"

Setting Content-Type in an Umbraco /Base service

The Umbraco /Base system is great for creating simple REST-like services. You can use the RestExtensionMethod attribute to instruct Umbraco to return your response as XML or not. But what is “not”? Apparently it means set Response.ContentType to “text/html”. But what if the returned data should be sent using a different mime type? Setting the ContentType manually like

HttpContext.Current.Response.ContentType = "application/json"

will not do the trick. Umbraco /Base will override it with “text/html” if you are returning a string from your service method.

What you need to do is to change your method return signature to “void” and write your data directly to the HttpResponse, like:

HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.Write(stringWriter.ToString());

Umbraco will not override the content type for “void”-methods. Below is a full example.

[RestExtension("Member")]
public class MemberService
{
	[RestExtensionMethod(returnXml = false, allowAll = true)]
	public static void Json()
	{
		var json = "{ \"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25 }";

		// Write response and set content type
		HttpContext.Current.Response.ContentType = "application/json";
		HttpContext.Current.Response.Write(json);
	}
}