Peter Morlion logo

Returning JSON or HTML from one contoller

Let me set the stage for this post first. Peergroups.be, the sharing economy website I develop for the non-profit WijDelen, is based on ASP.NET MVC. So I have a bunch of Controller classes with methods that end with return View(model);. Our first goal was to have a web application running as quickly as possible. Now […]

Generating a JWT in .NET 4.5.2

I recently had to generate a JSON Web Token (JWT) as a response from an login request to an api. The idea is to POST the user’s credentials from a mobile app, and to respond with a JWT. The mobile app can then verify that the user has logged in correctly. A quick introduction to […]

A generic JsonConverter for Dictionaries and JSON.NET

Update: In the 7.x release of Json.NET, a DictionaryKeyResolver was added that might be able to fix this problem too. I haven’t used it yet, so I can’t really say, but you might want to check it out. JSON.NET is a great tool and it already handles Dictionaries well, unless your keys are classes (as […]

Serializing private fields with JSON.NET and GetSerializableMembers

JSON.NET can handle serializing and deserializing private fields, but you have to tell it to do so. In the past, you had to set the DefaultMembersSearchFlags property of the ContractResolver of your settings. But this property is now marked obsolete. The documentation/Intellisense tells you to override GetSerializableMembers instead. But I’ve found there’s just one extra […]