ASP.NET WebAPI is a powerful tool for creating APIs quickly and efficiently in .NET. In fact, it takes minimal effort to expose your data through WebAPI though this is both a curse and a blessing. Blessing because it's so easy, curse because you need to be very careful of what you expose. You need to ensure that you're not exposing unwanted information and only provide authenticated access when necessary. Securing WebAPI is a big subject so I'll leave that for another post. Today, I'll show you how to create WebAPI controller methods that take optional parameters. 1. Using default …[read more]
Showing all posts tagged: '.Net'
I have blogged about application logging in .NET a few times, here and here. It seems that every iteration gets better than the one before - the logging frameworks, not my posts :) Logging has always been important but for some odd reason it is either too complicated to implement or too clunky. In the beginning, we had strongly coupled implementation using one of the established logging frameworks (log4net, nLog etc). Then we learned from our mistakes and moved on to the Common.Logging API which abstracted things quite a bit and made logging more accessible. The goal behind this evolution …[read more]
Are you still using XML files to store your application settings? Are you still placing your website properties in the web.config? Have you developed a nifty, cool, special library to manage XML files full of configuration properties? Do you, like me, find XML extremelly annoying even with all the new APIs such as LINQToXml? Sureley there must be something better out there? Well look no more, because I have the solution! Let me introduce you to ConfigR, the excellent little tool written by Adam Ralph. What is ConfigR you may ask? As Adam elegantly pitches it: ConfigR allows you …[read more]
In an earlier post I described how the Common.Logging API can help us abstract logging in our application by hiding the implementation details and allowing us to use different logging providers (NLog, Log4Net etc) in a modular, plug-n-play way. In this post, we will examine how to combine Common.Logging with Log4Net in order to output log messages to a file. 1. Install the right NuGet packages in the right order Before beginning, I will assume that all your assemblies already implement the Common.Logging API. If not, then go through my post to see how to add logging …[read more]
If you are like me, then you spend most of your day in front of your laptop/desktop and a couple of screens. So it makes sense that you use the best tools available to make your life and work easier. This was my goal when I decided to set up my home dev rig to ensure that I enjoy it as much as I can. So, what is my current setup and what tools do I use to make development as easy and enjoyable as possible? I will start with the hardware and then move on to software. 1. …[read more]
Prior to ASP.NET MVC 5, the only way to bind an enum to a drop down list in an MVC view was to roll out your own HtmlHelper, which is the best way to extend MVC's functionality. These days, with MVC 5 at your disposal, you can bind any enum to a view control easily by calling the "oh so handy" EnumDropDownListFor HTML helper. Details on the helper can be found here and works like any other build in HTML helper, with a model, a model property and a bunch of additional attributes that allow you to decorate your …[read more]