ASP.NET has had a bad rap for many years now. A lot of it seems to be because of the "ASP" portion of its name. Just like PHP classic ASP was horribly abused and many developers have been forced to slog through some of the worst, most impossible to support code, ever written by humans (were these people actually human though?).

ASP.NET != Classic ASP

ASP.NET isn't actually a single thing, it really seems to encompass all of the Microsoft web facing technologies. MVC5, Razor, WebForms (ewe), SignalR (awesomeness), and Web API to name just a few.

I am a huge fan of ASP.NET MVC, 4 really blossomed but 5 with its built in async controllers is just a thing of beauty. Here's why.

Forms

Handling user input in web applications has historically been a very verbose process.

<input type="text" name="element1" />

Becomes

Request["element1"]

That's not a lot of fun if you have to deal with lists of items, or even just a 20 field form.

MVC actions have you covered though

public class FormModel
{
    [Required]
    public string Name { get; set; }
    [Email]
    [Required]
    public string Email { get; set; }
    [PhoneNumber]
    [Required]
    public string Phone { get; set; }
}

public ActionResult Save(FormModel model)
{
    // Not only does it auto map your fields to your model it will also validate the form.
    if(ModelState.IsValid)
    {
        // Save it.
        // And with LINQ! (assuming Entity Framework)
        myDatabase.MyClientList.Add(model);
        myDatabase.SaveChanges();
    }

    // or return back with a list of errors
    // such as "The Email entered was not a valid Email"
    return View(model);
}

When I started to uncover the power in this system I wanted to cry thinking of the hundreds of hours I've spent in my life just mapping form fields, let alone writing validation junk.

What about making the form though.

Well, if you don't care you can literally just have a view like this:

@model FormModel

@using(Html.BeginForm()){
    @Html.ValidationSummary()

    @Html.EditorForModel()

    <input type="submit" value="Save" />
}

ValidationSummary() will write out a list of all of the model's validation errors. EditorForModel() will generate all of the HTML needed for the form fields along with labels and validation messages next to the form fields. MVC5 also implements the CSS classes for Bootstrap CSS automatically. There are some NuGet packages that will change them to map to other various Bootstrap type CSS.

Using the Razor form generation you can also very easily add client side validation by simply including jquery.validate.unobtrusive.js from the Scripts folder.

User Accounts

The amount of websites who manage to leak badly/non encrypted passwords seems to grow every week, and one of the many reasons that ASP.NET MVC5 accounts are securely managed through OWIN which handles hashing and salting passwords automatically for you.

The default MVC4/MVC5 web applications include all of the boiler plate code for accounts including registration, password changing, and third party login through OAUTH2 (Twitter, Microsoft Account, Google, Facebook, etc).

About Author

Siva Katir

Siva Katir

Programmer working at MGM Solutions in Bellingham Washington.