HomeWork with meBlogAboutContact
Book Review
Professional ASP.NET MVC 5
Frederik Banke
Frederik Banke
May 26, 2018
4 min

Table Of Contents

01
My notes for each chapter
02
Chapter 6
03
Chapter 7: Membership, Authorization and Security.
04
Chapter 8: AJAX
05
Chapter 9: Routing
06
Chapter 10: NuGet
07
Chapter 11: ASP.NET Web API
08
Chapter 12: Single Page Applications with AngularJS
09
Chapter 13: Dependency Injection
10
Chapter 14: Unit Testing
11
Chapter 15: Extending MVC
12
Chapter 16: Advanced topics
13
Chapter 17: Real world example

The book is published in 2014 so it is starting to show some age. Even though ASP.NET MVC 5 is the last version until it changed the name to ASP.NET MVC Core which is in version 2, see the version history here. So why read a four year old book? Many projects still use MVC 5 and it allowed me to gain an overview of the technology before diving into MVC Core. Unless you have a particular interest in MVC 5 I would recommend a book about MVC Core instead.

At 624 pages and 17 chapters, I read it in a couple of weeks. It does start to show it’s age when referencing jQuery and AngularJS, it is rather old versions mentioned. But the chapters about the MVC framework are sound and contains a good walkthrough about each main feature of the framework. If you need a primer on MVC 5 I will recommend it.

My notes for each chapter

When I read it helps me to write a few notes for each chapter to make it easier to remember. Hope it helps someone.

  • Chapter 1: Gives a historical walkthrough of how MVC has evolved in the .net ecosystem.
  • Chapter 2: Gives a high-level presentation of how controllers are used. A bit superficial.
  • Chapter 3: Introduces the razor templating engine and gives a high-level overview of how to use layouts and the Razor syntax
  • Chapter 4: Description about how models relate directly to Entity Framework. How to use View specific models. Description of model binding where we should be aware of over-posting attacks. Using the bind attribute this can be avoided.
  • Chapter 5: Forms and HTML helpers. ASP.NET uses HTML helpers like Html.BeginForm() to help generate HTML. The purpose of the helpers is to tie more easily into the backend so fewer values are hardcoded.

Reuse HTML components is called partial views and allows the developer to separate an HTML structure into a file that can be rendered in many places, like this:

@Html.Partial("AlbumDisplay ")

Chapter 6

Validation. ASP.NET allows a developer to reuse the same validation mechanism both in the backend and the frontend, skipping the need to duplicate code. It is controlled by attributes, like adding a [Required] attribute to a field in a model.

It even supports validating a field clientside by a callback to the server.

public string UserName { get; set; }

This will call the CheckUserName function to validate the field.

Error messages are also handled.

Chapter 7: Membership, Authorization and Security.

Security is controlled using attributes on the controllers. Using either roles or claims. ASP.NET come with a complete identity system that you can use to get running fast. It uses the ASP.NET identity system. Be aware that 2.0 is released after the book is written.

It supports external auth systems like OAuth, Windows Auth, Facebook, Google and so on.

The chapter spends many words on describing why issues like XSS is a problem. No really worth a read in my opinion. There are better resources for that.

A hint for making configuration easier is to use retail deployment configuration. It allows you to set a special configuration variable on the machine so it knows if it is a development or production machine.

The file is located at %windir%\Microsoft.NET\Framework\\<frameworkversion>\Config\machine.config.

Chapter 8: AJAX

Here the book shows age, much of jquery can be replaced by standard JavaScript by now. Lots of info about how jquery works.

Serverside validation can be pushed to clientside automatically. A little bit around bundles but not much, using bundles you can package js and CSS files so they can be preprocessed by ASP.NET

Chapter 9: Routing

Routing is not part of ASP.NET MVC but actually part of ASP.NET. Attributes can define routing, but so can the traditional approach using a code in a centralized place.

Routes can be added both to the controller class and the action methods and allow pattern matching. Routing constraints can be added using both data types and regex.

If you want to unit testing routes the books provide a few tips, but it does not work with attribute routes, which is the modern approach.

Routes can be used to generate links from Razor - use named routes to avoid problems.  For debugging routes the DebugRouteHandler is handy

Chapter 10: NuGet

Walkthrough of how to use NuGet, both to download/install packages and to publish. Not very ASP.NET specific.

Chapter 11: ASP.NET Web API

Separate framework - notice that in ASP.NET Core they are combined into the same framework.

Async by default, the output is mapped to different formats based on the request(JSON, XML and so on).

To help to generate documentation the framework automatic discovers the API endpoints and can use that to generate documentation.

The framework supports tracing(logging) just plugin your favorite logging library and it will start tracking automatically.

Chapter 12: Single Page Applications with AngularJS

Very AngularJS specific uses Web API as the backend. Not worth a read because the version of AngularJS that is used is deprecated.

Chapter 13: Dependency Injection

There is no default implementation for dependency resolver, just an interface.

ASP.NET supports two different service models. competitive services and cooperative services. For Competitive services, the first service that can serve the request handles is, the remaining services are not asked. With Cooperative services, every service is allowed to process the request.

Controllers with constructor parameters can be constructed with Dependency Injection and MVC will instantiate them using a controller activator class.

Web API Dependency Injection is a bit different, supports scopes, but I did not find it very useful.

Chapter 14: Unit Testing

General advice on unit testing and TDD. Only a few hints to how it is possible to implement unit tests in ASP.NET MVC.

Chapter 15: Extending MVC

Advanced topics which most will never use, but is nice to know about. I guess that by the time you get to need this you will just use the Microsoft documentation directly.

Chapter 16: Advanced topics

When outputting ASP.NET MVC supports two different modes. Either responsive web design, or display modes where the server guess which device did the request and serves different HTML based on that.

In my opinion, responsive web design is the correct way to go, at least for the time being.

Tips about templated razor delegates (lambda for razor templates).

Chapter 17: Real world example

Building a website. Actually, a good read to understand all of the concepts. Most of the reading will be in the supplied code. The code can be found here.


Tags

#c-sharp

Share

Frederik Banke

Frederik Banke

Code Coach

I teach developers how to improve the code they write. I focus on how they can implement clean code and craftsmanship principles to all aspects of their code.

Expertise

Clean Code
Refactoring
TDD
C#

Social Media

linkedingithubwebsite

Related Posts

C# 7.0
C# 7.0 in a Nutshell
July 01, 2018
8 min
© 2024, All Rights Reserved.
Powered By Earl Grey
Icons made by Freepik.com from Flaticon.com

Quick Links

About MeContact

Social Media