andrewlock / asp-dot-net-core-in-action

Source code examples for ASP.NET Core in Action
MIT License
208 stars 122 forks source link

Book project for ASP.NET Core in Action

This repository contains the code samples for ASP.NET Core in Action.

Note Some projects include 1.x versions of projects as well as 2.0 versions. Projects are essentially equivalent and are found in a folder indicating the .NET Core version.

Chapter 1

No code samples

Chapter 2

Chapter 3

Chapter 4

Chapter 5

No code samples

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

Chapter 13

Chapter 14

Chapter 15

Chapter 16

Chapter 17

Chapter 18

On Windows, you can generate a certificate using the Install-Certificate.ps1 PowerShell script. This will create a self-signd certificate and trust it on Windows.

You can generate a certificate on Ubuntu using install_certificate.sh. This uses localhost.conf to create a self signed certificate, and trusts it. On Linux, not all applications use the same store, so you may have to trust it explicitly for those applications. Use password testpassword to create the certificate.

Three endpoints are configured:

  1. An http endpoint at http://localhost:5001/api/values
  2. An https endpoint configured directly in code at https://localhost:5002/api/values
  3. An https endpoing configured externally by loading from hosting.json at https://localhost:5003/api/values

The path /api/values/1 has been decorated with a [RequireHttps] attribute, which will force the URL to redirect from http to https. Note however, that as we are not using the standard https port (443), the redirect will not work for this example. Alternatively you can enforce SSL across the whole site by uncommenting the RewriterMiddleware in Startup.Configure.

Chapter 19

Chapter 20