ASP.NET Core MVC

I find myself throwing together web API’s and small web apps regularly for various purposes. Each project contains the same setup such as logging, managed config, api areas, api versioning, etc… Often I end up going into a previous project and copy-paste. I thought I would save myself a bit of time by documenting the process for each feature here.

Setting up new .Net projects

Intro I have been a developer for somewhere around 30 years now. In my time I have created a few thousand projects of varying sizes, and for every new iteration I try to improve slightly on my previous. I also see a lot of code from others, and most what I see don’t seem care … Read more

ASP.Net 5 Areas

Visual Studio 2015 with ASP.Net 5 doesn’t support Areas in the GUI editor. Hopefully that will come, but until then here is a simple workaround. Create folder structure In the root of your project (not wwwroot) create the folder structure for Areas manually. In this example I created an area named “Foobar”. Edit Startup.cs to … Read more

Multiple deployment configs in one config file with ACL

Most projects that is deployed into production require some kind of config change upon deployment. Often it is the connection string that varies, but it can be any number of custom settings. Forgetting to change the config file when deploying, or forgetting to change config back on your dev machine after deploying can have disastrous … Read more

Alternative directory layout for MVC

In .Net the MVC pattern is implemented through a template project. The project is set up for you when you create a new MVC application and imposes certain patterns on you. And that is exactly what MVC is, a pattern. By default you will create a controller, a view and a model. Usually you add … Read more

.Net tools to use: log4net

log4net http://logging.apache.org/log4net/ Description Free popular logging system developed by Apache Foundation. Difficulty 1 line at top of each class. A standard XML-section in web.config. Sample usage: [sourcecode language=”csharp”] // At the top of every class you set up a static logger with the class name (retrieved through System.Reflection) private static log4net.ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType) // … Read more

.Net tools to use: Nini

http://nini.sourceforge.net/ Nini   Description An uncommonly powerful .NET configuration library. Use this for reading web.config (instead of .Net built-in System.Configuration…) and any other .ini-file or .xml-file containing configuration. Difficulty 2 lines to read (usually called at page_load or similar). Sample usage: [sourcecode language=”csharp”] // Set up our config source as web.config or app.config internal static … Read more