Interesting Extension Hack To Get Around NullReferenceException's

Today I came across an interesting extension pattern that I didn’t know how the runtime would react. Normally when you do something like the following: string s = null; Console.WriteLine(s.Trim()); // throws NullReferenceException You get a NullReferenceException meaning that you didn’t first check to see if the object was null before trying to call one of its methods. This is pretty common and results in patterns that usually look like this: ...

April 24, 2008 · 2 min · 313 words · Nick Berardi

Creating a Facebook Application using MVC

Facebook has been growing in popularity ever since it was released on February 4th 2004 at an almost unstoppable pace. Up until May 24th, 2007, it wasn’t much different than MySpace (or insert your favorite social network here), however on that day they rolled out a SDK that turned Facebook from a destination website to a platform that let any developer interact with their almost 71 million users. You can read more about the history of Facebook at Wikipedia. ...

April 11, 2008 · 4 min · 720 words · Nick Berardi

Why is JSON Deserialization so Important to Developers?

Recently I have been working on a RESTful interface for a Web 2.0 project that I will be releasing very soon. And one of the self imposed requirements that I set out to achieve was to have the RESTful interface output the same structure JSON as XML. This way that any developer using the interface would feel comfortable using the JSON and XML interchangeably. But, I have been having a lot of trouble recently getting my JSON and XML to output the same structure when using the built in .NET methods. I have tried the following: ...

April 3, 2008 · 3 min · 542 words · Nick Berardi

Force MVC Route URL to Lowercase

So one of my pet peeves in web development is mixed case URL’s. And I usually make sure that all my URL’s in my personal projects follow this standard. I also believe, contrary to my URL case standard, that my code should follow standards .NET naming techniques, such as Pascal casing for my method names. These two naming standards come in to conflict with MVC because the name of the action method in the controller is used in its native Pascal case. Which generates URL’s that look like this: ...

March 31, 2008 · 2 min · 234 words · Nick Berardi

ASP.NET MVC: Securing Your Controller Actions (The .NET Framework Way)

So I just read Rob Conery’s blog post on Securing Your Controller Actions in MVC. I was a little perplexed about why guys at Microsoft love to reinvent stuff they have already done. I know Rob Conery is a really smart guy and has a wonderful grasp of the .NET framework, so I would have to assume he knows about what I have outlined below. My only guess is that he just wanted to re-invent something that is already built in to the framework using his own code. ...

March 13, 2008 · 3 min · 461 words · Nick Berardi

ASP.NET MVC Preview 2 CAPTCHA using ActionFilterAttribute

My last article on ASP.NET MVC CAPTCHA was very well received by many of my readers and it even caught the eye of the DotNetKicks crowd. Now that MVC Preview 2 was released last week, many new features make encapsulating my CAPTCHA control even easier. Most notably is the ActionFilterAttribute which allows you to override the Pre and Post action events for any action the attribute is applied to. Basically everything works the same as it did in the previous article. I just modified things for MVC Preview 2. To validate the CAPTCHA you add the attribute CaptchaValidation to the action. ...

March 9, 2008 · 1 min · 203 words · Nick Berardi

Singularity Source Code Released to CodePlex

Just saw on OSNews that Microsoft Research has just released the Singularity Source Code on CodePlex. Microsoft has released source code from the Singularity research project onto Codeplex under an academic, non-commercial license. “The Singularity Research Development Kit is based on the Microsoft Research Singularity project. It includes source code, build tools, test suites, design notes, and other background materials. The Singularity RDK is for academic non-commercial use only and is governed by this license.” ...

March 4, 2008 · 2 min · 266 words · Nick Berardi

ASP.NET MVC CAPTCHA

Note: Most recent update for MVC Release Candidate 3 is out. So my MVC application that I have been working on required a CAPTCHA today. The problem is that all of the solutions out there, that I could find for ASP.NET, are control based and I wanted a more MVC approach. I know I could have easily implemented one of them using the Html.RenderControl(), however I want to use a MVC approach to the CAPTCHA authentication box. So I started out with Jeff Atwood’s CAPTCHA Control made for ASP.NET 2.0 in VB.NET 2005. I then converted it to C# and modified and expanded on it for the MVC framework. The following is the result of my work. ...

March 3, 2008 · 3 min · 620 words · Nick Berardi

ASP.NET MVC Route Validation and SEO

Recently I have been using the ASP.NET MVC framework for a project at work. And one of the requirements was that certain data inputed in to the URL be tightly verified. I originally thought that data was verified by the type specified in the ControllerAction, however I came to find out that it wasn’t. So if you have say a page number and the user enters a letter in the URL the application just proceeds on it’s marry way. For example on the Kigg site: ...

February 27, 2008 · 3 min · 621 words · Nick Berardi

What I Learned About MVC On Day One

I am really blown back about how fast and easy MVC is to develop with. I know the guys at Microsoft do a good job with their .NET coding, but I am really impressed by the forethought they put in to MVC. It builds on top of the standard ASP.NET package, but does it in such a way that makes it lean on top of the already feature-rich (read bloated) ASP.NET Page object. It really doesn’t feel like I have all that baggage anymore. ...

February 25, 2008 · 1 min · 165 words · Nick Berardi