Home Web Development Learning ASP.NET Core 2.0

Learning ASP.NET Core 2.0

By Jason De Oliveira , Michel Bruchet
books-svg-icon Book
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $39.99 $27.98
Print $48.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    What is ASP.NET Core 2.0?
About this book
The ability to develop web applications that are highly efficient but also easy to maintain has become imperative to many businesses. ASP.NET Core 2.0 is an open source framework from Microsoft, which makes it easy to build cross-platform web applications that are modern and dynamic. This book will take you through all of the essential concepts in ASP.NET Core 2.0, so you can learn how to build powerful web applications. The book starts with a brief introduction to the ASP.NET Core framework and the improvements made in the latest release, ASP.NET Core 2.0. You will then build, test, and debug your first web application very quickly. Once you understand the basic structure of ASP.NET Core 2.0 web applications, you'll dive deeper into more complex concepts and scenarios. Moving on, we'll explain how to take advantage of widely used frameworks such as Model View Controller and Entity Framework Core 2 and you'll learn how to secure your applications. Finally, we'll show you how to deploy and monitor your applications using Azure, AWS, and Docker. After reading the book, you'll be able to develop efficient and robust web applications in ASP.NET Core 2.0 that have high levels of customer satisfaction and adoption.
Publication date:
December 2017
Publisher
Packt
Pages
516
ISBN
9781788476638

 

Chapter 1. What is ASP.NET Core 2.0?

The first preview release of ASP.NET came out almost 15 years ago as part of the .NET Framework. Since then millions of software developers have used it to build and run all types of great web applications. Over the years Microsoft has added and evolved many of its features until coming up with a complete redesign of the ASP.NET Framework called ASP.NET Core in June 2016. After ASP.NET Core 1.0 and 1.1, version 2.0 is the third and latest installment of ASP.NET Core. Let's see what it offers and when it makes sense to use it in your projects.

ASP.NET Core 2.0 is a new open-source and cross-platform framework for building modern cloud-based applications, such as web applications, Internet of Things (IoT) applications and even mobile backend.

ASP.NET Core 2.0 applications run on the .NET Core Framework as well as on the full .NET Framework. The ASP.NET Core Framework was architected to provide an optimized development framework for applications, which have to be deployed either within the cloud or on-premises. It consists of modular components with minimal overhead, so you retain a high degree of flexibility when conceiving and implementing your software solutions. You can develop and run your ASP.NET Core 2.0 applications on Windows, Linux, and macOS.

In the following diagram you can see how the different .NET Framework versions and components work together:

ASP.NET Core 2.0 includes several architectural changes that result in a much leaner and more modular framework when compared to the framework that came before it. It is no longer based on System.Web.dll, instead, it uses a set of granular and well factored NuGet packages. This allows optimizing of applications to include just the NuGet packages that are really needed.

The benefits of a smaller application surface area include:

  • Better security
  • Reduced dependencies between components
  • Improved performance
  • Decreased optimized financial costs in a pay-for-what-you-use cloud consumer world

As a developer, when building applications based on the classic .NET Framework, you must choose between six application models (WPF, Windows Forms, Web Forms, Web MVC, Web API, and Xamarin), which can be confusing and not very productive.

With the release of the ASP.NET Core 1.0 and 1.1, this was optimized and reduced to three different application models, with the drawback that you cannot share code between them.

With ASP.NET Core 2.0, the number of application models was further reduced to two and code is now sharable, meaning that you can now reuse more than 90% of your code. For you as a developer, this makes you more productive and allows for switching between application models quickly and easily.

In this chapter, we will cover the following topics:

  • ASP.NET 2.0 features
  • Cross-platform support
  • Microservice architecture
  • Working with Docker and containers
  • Performance and scalability
  • Side-by-side deployments
  • Technology restrictions
  • When to choose ASP.NET Core 2.0
 

ASP.NET Core 2.0 features


The new Microsoft.AspNet.Core.All package contains all ASP.NET Core 2.0 features in a single library. It includes authentication, MVC, Razor, monitoring, Kestrel support and many others. They are explained in more detail later in the book.

Note

Note that if you want to selectively add packages one by one, you can still reference them manually instead of using the single packages that contain it all but then you will miss several advantages as you will see here.

The runtime store is an important new component shipped with ASP.NET Core 2.0. It contains compiled packages, which were compiled using the native machine language and it is key for improved performance. All applications using the Microsoft.AspNet.Core.All package benefit from it, because they do not need to be deployed with all the dependent packages anymore. Everything is already there, so their deployment size will be reduced and their execution time will be optimized.

ASP.NET Core 2.0 allows you to create well-factored and testable web applications that follow the Model-View-Controller (MVC) pattern. We have dedicated a full chapter to this topic later in the book.

Furthermore, you can build HTTP services with full support for content negotiation using custom and built-in formatters such as JSON or XML as well as RESTful services.

ASP.NET Core 2.0 fully supports Razor which contains an efficient language for creating your views and Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files.

Model binding automatically maps data from HTTP requests to action method parameters and model validation automatically performs client and server side validation.

In terms of client-side development, ASP.NET Core 2.0 is designed to integrate seamlessly with a variety of client-side frameworks including AngularJS, KnockoutJS, and Bootstrap.

Additionally, it provides the following fundamental improvements:

  • ASP.NET MVC and Web API have been combined into a single framework
  • Modern client-side frameworks and development workflows
  • Environment-based configuration system ready for cloud hosting
  • Built-in dependency injection functionalities
  • New light-weight and modular HTTP request pipeline
  • Host the same application in IIS, self-host, Docker, Cloud and even in your own processes
  • Hosts multiple versions of an application or a component side-by-side
  • Ships entirely as NuGet packages
  • New tooling that simplifies modern web development
  • Simplified csproj file, making it easier to work with development environments other than Visual Studio (on Linux and macOS, for example)
  • The Program.cs class has been extended to fully automate the integration of Kestrel, the setting of the ContentRootPath, loading the configuration files, initializing the logging middleware, and other steps by only calling a single method
  • The Startup.cs has been simplified by moving logging and configuration into the WebHost builder initialization
 

Cross-platform support


As explained before, the ASP.NET Core 2.0 framework has been built, from the beginning, with cross-platform support in mind. It supports a wide variety of operating systems and technologies such as Windows, Linux, macOS, Docker, Azure, and others.

ASP.NET Core 2.0 currently supports the following Linux distributions:

  • Ubuntu 14, 16
  • Linux Mint 17, 18
  • Debian 8
  • Fedora
  • CentOS 7.1 and Oracle 7.1
  • SUSE Enterprise Server 64 bits
  • OpenSuse 64 bits

Concerning macOS, it currently only supports (other versions might be added later):

  • macOS 10.11
  • macOS 10.12

For application development, you may develop on Windows using Visual Studio or Visual Studio Code and then deploy your ASP.NET Core 2.0 application to your target system.

Note

Note that the target system can use a completely different underlying operating system. For instance, you can develop and test on Windows and then deploy your applications to a Linux server for performance, stability or cost reduction reasons.

If you choose so, you can of course directly develop on Linux and macOS using several system-specific source code editors. On Linux, you could use Visual Studio Code, VIM/VI, Sublime, or Emacs for example. On macOS, you could use Visual Studio for Mac, Visual Studio Code or any other Mac-specific text editor.

The Visual Studio 2017 or Visual Studio Code developer environments would be the preferred choice though, since they provide everything necessary to be highly productive and to be able to debug and understand your code as well as navigate within it easily. That is why we are going to use those IDEs throughout the rest of the book.

After building your application, you can use several web servers to run it. Here are some examples:

  • Apache
  • IIS
  • Kestrel self-host
  • Nginx
 

Microservice architecture


Microservices also known as the microservice architecture, is an architectural layout that structures an application as a collection of loosely coupled services, which implement business capabilities. It can be used to build e-commerce system, business application, and IOT.

ASP.NET Core 2.0 is the best candidate when you want to embrace this system architecture. The ASP.NET Core 2.0 framework is lightweight and its API surface can be minimized to the scope of a specific microservice. A microservice architecture also allows you to mix technologies across service boundaries, enabling for a gradual transition to ASP.NET Core.

Notice that microservices built with ASP.NET Core 2.0 can work together with services using other technologies such as the full classic .NET Framework, Java, Ruby, and even other more legacy technologies. This is a big advantage when you need to progressively transform monolithic applications into more (micro)service-oriented applications.

You are not bound to a specific underlying infrastructure, instead, you have a wide choice since ASP.NET Core 2.0 supports nearly all the technologies that you can think of today. Additionally, you can modify the infrastructure when needed so there is no technological lock-in for applications that have been developed based on it.

Your primary choice for orchestrating and managing microservices written in C# efficiently and at high scale, on-premises, and in the cloud, should be Microsoft Service Fabric. It was conceived exactly for that and is used by Microsoft for various Azure services (SQL Database, and more) for many years already.

A microservices Docker container approach might also fit your needs, we are going to explain its use cases in the next paragraphs. To sum it up, ASP.NET Core 2.0 is the ideal choice for implementing and hosting your microservices in any kind of technical environment.

 

Working with Docker and containers


Docker and containers are everywhere at the moment. Everybody is speaking about them and there are so many use cases where they seem to be a great fit. They provide an efficient, lightweight and self-contained approach for packaging applications with their dependencies while re-using the underlying operating system files and resources.

They are a perfect fit for microservice architectures, but can also be used for any other application archetypes. They work exceptionally well together with ASP.NET Core 2.0 applications since both have been conceived with modularity, performance, scalability, lightweight nature, and efficiency in mind.

Note

Note that Docker container images including ASP.NET Core 2.0 applications are much smaller than images with classic ASP.NET applications, meaning that they are faster to deploy and to start-up.

Both, Docker containers and the ASP.NET Core 2.0 framework, provide full cross-platform support (Windows, Linux, and macOS). Furthermore, you can host your containers on-premises and in the cloud. You can use Azure for example, either via IAAS deployments or via Azure Container Services, which additionally allows for mixing and matching different operating systems and technologies.

 

Performance and scalability


If you need the best possible performance and support high scalability scenarios then you need to absolutely use ASP.NET Core 2.0 and the underlying .NET Core Framework. ASP.NET Core 2.0 has been built from the ground up for high performance and high scalability scenarios. It really shines in these areas and it can be considered as the best choice.

It is ten times faster than classic ASP.NET, you can even think of it to be the fastest web application runtime in the .NET world currently available!

Furthermore, it provides the best solution for microservices architectures, where performance and scalability are extremely important. No other technology is as efficient while consuming such low system resources, which also leads to reduced infrastructure and cloud hosting costs.

 

Side-by-side deployments


If you want to be able to install applications with dependencies on different versions of the .NET Framework, then you should consider using the ASP.NET Core 2.0 framework, since it provides 100% side-by-side deployment capabilities.

Side-by-side deployments of different .NET Core and ASP.NET Core versions allow for having multiple services and applications on the same server. Each of them can be using their own dedicated versions of the respective frameworks, thus eliminating risks and saving money when doing application upgrades and common IT operations.

 

Technology restrictions


Please look carefully at the technologies shown in this section. If you use a technology or framework within your current application, which is listed here and which is not (yet) supported, then you might find it difficult or even impossible to migrate to ASP.NET Core 2.0.

Not all current .NET Framework technologies are available in ASP.NET Core 2.0 and some might never be ported over, since they do not comply with the new .NET Core specific paradigms and patterns.

The following list shows the most common technologies not directly found in ASP.NET Core and .NET Core, knowing that some can be used via the multi-targeting features:

  • ASP.NET Web Forms applications: The legacy Web Forms technology is only available using the full classic .NET Framework, you cannot use ASP.NET Core and .NET Core for these types of applications.
  • ASP.NET Web Pages applications: They are not included in ASP.NET Core 2.0 as such, but it is possible to use the Razor web pages engine to provide the same functionalities.
  • ASP.NET SignalR applications: Currently, ASP.NET SignalR is not available for ASP.NET Core. However, you can find a first preview version in the corresponding server-side and client library GitHub repositories, so they should be included in one of the next releases.
  • WCF Services: ASP.NET Core 2.0 contains a WCF client for accessing WCF services, but creating WCF services is not supported. This feature might be added in future releases though.
  • Workflow Services: Windows Workflow Foundation, Workflow Services, and WCF Data Services are not supported and there are no plans for adding them to ASP.NET Core in the future.
  • WPF and Windows Forms applications: Windows Presentation Foundation and Windows Forms cannot be built with ASP.NET Core, it would go against the cross-platform paradigm. You could, however, replace your WPF applications by UWP applications provided by the XAML2 Universal standard.

Not all .NET languages are currently supported by ASP.NET Core 2.0. For example, F# does not have any tooling support. Visual Basic support has been added in the latest version of Visual Studio 2017. There will be more and more languages that will be supported.

In addition to the official ASP.NET Core roadmap, there are other frameworks and technologies, that are planned to be ported over to .NET Core in the next months. To get further information on what will be ported over and what will not, go to the GitHub repository of the .NET Core Libraries (https://github.com/dotnet/corefx).

For those that are planned, there is no assurance that they will really get ported over, though. But you will find a good indication of what you can expect in the next versions of ASP.NET Core. Note that you can, in some cases, use the multi-targeting features of ASP.NET Core 2.0 for being able to call frameworks that are currently not directly supported by ASP.NET Core 2.0.

If you care about a specific framework or component that you need within your projects, consider participating in the discussions on GitHub. Maybe others will have the same requirements and Microsoft decides to prioritize their .NET Core migration accordingly.

Some Microsoft services, and even some third-party platforms, do not support ASP.NET Core. For example, some Azure services such as Service Fabric Stateful Reliable Services and Service Fabric Reliable Actors require the full classic .NET Framework.

Also, sometimes ASP.NET Core SDKs are not provided or not yet available. In the meantime, you can always use the equivalent REST APIs instead of the client SDKs and then replace them later. Be assured, all Azure services are going to support ASP.NET Core in the future as can be seen on the respective product roadmap.

 

When to choose ASP.NET Core 2.0


After having seen the various features and functionalities provided by ASP.NET Core 2.0, you could ask yourself if it will replace the full classic .NET Framework in the future. It is true that ASP.NET Core 2.0 and the underlying .NET Core Framework provide some major enhancement and performance improvements, but there are still some specific scenarios, where those new application patterns do not apply and where the full .NET Framework will be the best and sometimes even the only choice.

Migrating your whole existing applications to ASP.NET Core right from the start might be difficult or even impossible to do. You should think about how to transform your applications progressively to lower the risk of failure or over-complexification and give yourself time to really understand the new patterns and paradigms.

You could start for instance by only using ASP.NET Core 2.0 for all new developments, then see how to migrate your legacy code later and sometimes even leave it be since there will be no real benefits for migrating it over. If you are really interested in the migration topic, please consider the appendix, since we have a full chapter dedicated to this important topic.

ASP.NET Core and the .NET Core Framework get more and more framework and client library support each day. Microsoft, tool and framework vendors, and the different developer communities work hard to provide a large set of functionalities for allowing feature-rich and high performing web applications. Everybody wants to work on this promising technology that could shape the future in a sustainable way.

The possibility to use .NET Core and .NET Framework libraries together at the same time when using .NET Standard 2.0 extends the possibilities even more and gives developers a temporary solution until every important feature and every major framework will be available in .NET Core.

To recap what has been discussed in this chapter, you should use ASP.NET Core 2.0 for your server applications when:

  • You have cross-platform needs
  • You are specifically targeting microservices
  • You want to use Docker containers
  • You need high performance and highly scalable applications
  • You need to put multiple applications with different .NET versions side by side
  • The presented technical restrictions do not apply to your application requirements
 

Summary


In this chapter, you have learned about the ASP.NET Core 2.0 framework and its features. You have seen that it includes everything necessary to work efficiently in a cross-platform environment while using microservices architectures and container technologies such as Docker.

Furthermore, you have learned that it provides very good performances and exceptional scalability for your web applications and that even side-by-side deployments are supported.

At the end, we have talked about technical restrictions and when it is advisable to use the ASP.NET Core 2.0 framework.

In the next chapter, we will talk about how to set up your development environment including either Visual Studio 2017 or Visual Studio Code as an integrated development environment.

About the Authors
  • Jason De Oliveira

    Jason De Oliveira works as a CTO for MEGA International, a software company in Paris (France), providing modeling tools for business transformation, enterprise architecture, and enterprise governance, risk, and compliance management. He is an experienced manager and senior solutions architect, with high skills in software architecture and enterprise architecture. He loves sharing his knowledge and experience via his blog, speaking at conferences, writing technical books, writing articles in the technical press, giving software courses as MCT, and coaching co-workers in his company. He frequently collaborates with Microsoft and can often be found at the Microsoft Technology Center (MTC) in Paris. Microsoft has awarded him for more than 6 years with the Microsoft® Most Valuable Professional (MVP C#/.NET) award for his numerous contributions to the Microsoft community. Microsoft seeks to recognize the best and brightest from technology communities around the world with the MVP Award. These exceptional and highly respected individuals come from more than 90 countries, serving their local online and offline communities and having an impact worldwide. Feel free to contact him via his blog if you need any technical assistance or want to talk about technical subjects. Jason has worked on the following books: .NET 4.5 Expert Programming Cookbook (English) WCF 4.5 Multi-tier Services Development with LINQ to Entities (English) .NET 4.5 Parallel Extensions Cookbook (English) WCF Multi-layer Services Development with Entity Framework (English) Visual Studio 2013: Concevoir, développer et gérer des projets Web, les gérer avec TFS 2013 (French)

    Browse publications by this author
  • Michel Bruchet

    Michel Bruchet works as an application architect for MEGA International, a software company in Paris (France), providing modeling tools for business transformation, enterprise architecture, and enterprise governance, risk, and compliance management. He has more than 20 years of experience as a senior architect, working on complex projects in IT and development departments.

    Browse publications by this author
Latest Reviews (8 reviews total)
I thought this course was for a beginner, but it starts slow and then it gets too complicated and convoluted with lots of projects and libraries, it was confusing and disappointing.
My reader had a lot of issues with their epub file, but they did not lock it, so they allowed me to reformat it to the point where I could use it.
Avevo bisogno di un libro che descrivesse in modo abbastanza approfondito e chiaro le peculiarità del framework ASP Net core 2, sono rimasto soddisfatto dell'acquisto.
Learning ASP.NET Core 2.0
Unlock this book and the full library FREE for 7 days
Start now