Create a Base Class for Your ASP.NET MVC Controllers

ASP.NET MVC Controller.  What have you done?

Here I am trying to follow the SOLID principles and create millions of tiny (microscopic even) classes and you come along with your 1 huge class that has a method for every single view I need.  How dare you!!

In all seriousness – the controller makes it a bit harder to follow the SOLID principles (as well as other design patterns).  In addition, if you want to create a class to get information that you will regularly need – you must call that class each time, which just gets a bit monotonous (even if it is static).

Solution? – Use a Base Class!

If you open one of your Controllers (Home.cs) you will see that it inherits System.Web.Mvc.Controller.  This is what allows us to use properties like RouteData and HttpContextBase or methods like View() and PartialView().  (For a more complete list of what properties/methods the Controller class gives us see this link).

Now lets assume you have some property that is very important to your company – but doesn’t mean jack to anyone else.  For example you sell one length of shoestrings – 76 inches.  Let’s say you want a ShoeStringLength property in ALL of your controllers, and you don’t want to reference some static class each time.  You could create a new Controller called BaseController (with the ShoeStringLength property), have that Controller inherit the System.Web.Mvc.Controller class (so that you have all of your MVC functionality available) and then have your Home Controller inherit your new BaseController class.

Using your own BaseController class will allow you to add properties and methods available in every Controller in your ASP.NET MVC app in a straightforward way!


Leave a comment

Posted by on March 6, 2012 in Software/Programming


102 Flavors of Doritos

I can’t believe it either.

Cool Ranch, you will always be the only one for me …

Leave a comment

Posted by on September 27, 2011 in Random


Ahhhh … change it back!

So, you just polished up your product!  Yay!  That bug that insults a visitor’s mom when he/she presses “Insult Me” is gone.  Firefox finally allowed you to use the ellipsis overflow property.  Something else is cool … Time to push.

Deployment process engage!

Uh ho …I think I broke it.

The old failed deployment.  Most people strive for perfect automated deployments … but most people aren’t quite there just yet (and would not pass the joel test).  Now what?  Well, if you built your own installer you probably spent hours devising some evil _BAK folder (well, I did) that you stored everything in and restored.  Sure, it worked, but it was a pain.

Well then how the $*#& should I do it then, you might be shouting at me right now.

Git!  While git is a great distributed SCM, it is also a great file control system.  So, using Git branching, I could:

  • Create a new branch (version) from my current branch.
  • Deploy my new files
  • When I have my problem, just switch back to my original branch.

A revert would take just seconds!  And, you could keep deleting the branch and trying until you git it right.

How fun!

Go Pens!

Leave a comment

Posted by on September 21, 2011 in Software/Programming


StackOverflow vs Experts-Exchange

So, you’re lost.  You want to make that tooltip just a little cooler.  Or, you can’t figure out why your SqlConnection throws some error that sounds like vomit (New request is not allowed to start because it should come with valid transaction descriptor … yes, that’s a real one).  Where do you turn?

  • Your friends?
  • Your mom?
  • Online Community?

Your Friends

Mostly, they have no idea what a computer is.  One time they recorded a macro in Excel, so they have C++ on their resume, but when it comes down to it they are a dead end.  Also, they may be calling you a nerd behind your back.

Your Mom

Crickets ….

Online Community

This is where I have had luck in the past.  And the two best online communities I can find are and

This was, for years, the best community out there (previously … I guess expert sex change wasn’t what they were going for).  While it wasn’t free, it was worth the few $’s a month to be able to ask a question and have an answer the same day, or next day max.  Gone were the days of posting to a ghost town Google Group, or some off the wall forum that has the same user count as  Finally,  a viable option for help!  It is still good to this day, and I have no complaints.

More recently, this seems to have overtaken Experts-Exchange as the de facto option for online dev help.  It is free (which breaks down the barrier of use) and questions get answered remarkably fast.  They have chat communities (mainly for bashing “dumb” question), and really go the extra step in actually being able to get you a job (Careers 2.0).  Plus they are created and run by the JoelOnSoftware/FogCreek guys, who I generally enjoy reading.

Who’s the best?

I personally like  I still have an account on Experts-Exchange, but I don’t think you can beat StackOverflow for speed, accuracy, snarkiness, and number of answers.

My StackOverflow Account

My Experts-Exchange Account

Go Pens!

Leave a comment

Posted by on September 20, 2011 in Software/Programming


This is My First Post!

WordPress eh?  Seems neat.

What a post.

Leave a comment

Posted by on September 16, 2011 in Random