C# OutputCache with subdomains

Published on May 4, 2018 by Jamie Munro

The other day I was working on a project that was leveraging OutputCache. This little attribute is a fantastic way to implement caching in an MVC project. It was being used as follows but it was not working when we had multiple subdomains sharing the same controllers and actions:


public ActionResult Index()


return View();


Read more >

Tags: Optimization | ASP.NET

C# Convert date from UTC to EST

Published on Jun 7, 2017 by Jamie Munro

Every now and then I need to convert a date from Coordinated Universal Time (UTC) to Eastern Standard Time (EST).† I always found myself trying to remember "Where did I use this last?".† To avoid asking myself, I have now immortalized it on my blog.

Read more >

Tags: ASP.NET | c# | timezones

How to return a CSV from ASP.NET Web API using C#

Published on May 4, 2017 by Jamie Munro

ASP.NET Web API is a framework that is built upon the MVC (Model View Controller) principal to assist in rapidly building a RESTful API using the .NET framework.

By default Web API makes it easy to return common HTML content types, such as: JSON and XML.† However, it requires a little bit more work to return a CSV using Web API.† Read on to learn how.

Read more >

Tags: ASP.NET | c# | web api | csv

Unit Testing Data Validation with MVC

Published on May 11, 2015 by Jamie Munro


You've added some data validation and you want to test it out in action. The data validation can be standard data annotations, custom data attributes, or data validation implemented via an IValidatableObject.


Unit testing data validation can be accomplished by creating a ValidationContext in conjunction with the Validator helper class. To demonstrate how this is accomplished, I will use the ValidationModel class I created in the Removing Data Validation from MVC Controllers. As you may recall this class contained an IValidatableObject that ensured if the boolean FixedQuantity was true, the MaxQuantity property must be null.

Read more >

Tags: validation | ASP.NET | mvc | Testing | unit testing | ivalidatableobject | validationcontext

Removing Data Validation from MVC Controllers

Published on May 6, 2015 by Jamie Munro


You require custom data validation that cannot be accomplished via the built-in data annotation validation attributes - or - your data validation requires access to multiple properties in your model.


Many times the easy answer is to place the validation inside of your controller. However, I'm a strong believer of placing data validation outside of your controllers and within your data model. This is commonly accomplished by adding data annotation above the properties, such as the [Required] attribute. Another common way is to create your own validation attributes.

This example will use a third way and that is to implement the IValidatableObject interface. This interface defines a Validate function that must be implemented and because it is inside of your data model it has access to all properties within your model.

Read more >

Tags: validation | ASP.NET | mvc5 | ivalidatableobject | validationcontext

Speeding up my unit tests

Published on Apr 28, 2014 by Jamie Munro

Advanced Automatic Ninject Bindings

Published on Jan 13, 2014 by Jamie Munro

Automatic Ninject Bindings

Published on Jan 7, 2014 by Jamie Munro

Automapper Performance Testing

Published on May 27, 2013 by Jamie Munro

Why the Repository Pattern

Published on May 20, 2013 by Jamie Munro

The Best Way to Prevent SQL Injection

Published on Sep 19, 2012 by Jamie Munro

What I Learned This Summer

Published on Sep 7, 2012 by Jamie Munro

MVC 3 Routing Example

Published on Oct 17, 2011 by Jamie Munro

20 Recipes for Programming MVC 3

Published on Oct 12, 2011 by Jamie Munro

20 Recipes for Programming MVC 3

Published on Oct 12, 2011 by Jamie Munro