ASP.
NET Core Tutorial for Beginners
Part 1 - [Link] Core Tutorial
Bahaa Mohammad Rashed
1
[Link] Core Tutorial
[Link] Core
[Link] Core MVC
[Link] Core Identity
Entity Framework Core
2
What is [Link] Core
[Link] Core is a cross-
platform, high-performance,
open-source framework for
building modern, cloud-based,
Internet-connected applications
[Link] Core is a redesign of
[Link] 4.x
3
DOTNET CORE ROADMAP
.NET CORE .NET CORE .NET CORE .NET CORE .NET CORE .NET CORE
1.0 2.0 3.0 3.1 5.0 6.0
June 2016 Aug 2018 Sept 2019 Dec 2019 Nov 2020 Nov 2021
4
[Link] Core Benefits and Features
Cross Platform Testability
One Programming
Model for MVC and Open-Source
Web API
Dependency
Modular
Injection
5
[Link] Core Benefits and Features
Cross Platform
[Link] Core applications can be developed and run
across different platforms like
Windows
macOS
Linux
[Link] Core applications can be hosted on
IIS
Apache
Docker
Self-host in your own process
6
[Link] Core Benefits and Features
One Unified Programming Model for MVC and
Web API
Both the MVC Controller class and the [Link] Web
API Controller class inherit from the same Controller
base class and returns IActionResult
IActionResult
ViewResult JsonResult
7
[Link] Core Benefits and Features
Modular
[Link] Core Provides Modularity with Middleware
Components
Both the request and response pipelines are
composed using the middleware components
Rich set of built-in middleware components are
provided out of the box
Custom Middleware Components can also be
created
8
Prerequisites
Basic HTML, CSS and C#
Prior MVC knowledge is helpful but not
required
Next : Tools required to build [Link] Core
Applications
9
[Link] Core Tutorial for Beginners
Part 2 - Setting up machine for [Link] Core Development
Bahaa Mohammad Rashed
10
Software for .NET Core Development
An Editor - VS, VS Code, Sublime, Vim,
Atom…
.NET Core SDK (Software Development
Kit)
11
Install Visual Studio 2022
Visual Studio Community Edition is
free
[Link]
ree
12
Install Visual Studio 2022
Select .NET Core Cross-Platform
Development Workload
13
Install .NET Core SDK
[Link]
Creating a New [Link] Core Web
Next Application using Visual Studio
14
[Link] Core Tutorial for Beginners
Part 3 - Creating [Link] Core Web Application
Bahaa Mohammad Rashed
15
Creating [Link] Core Web Application
Creating a new [Link] Core
Project in Visual Studio
The different project templates
that are available and what they
do
16
[Link] Core Tutorial for Beginners
Part 3 - Creating [Link] Core Web Application
Bahaa Mohammad Rashed
17
Creating [Link] Core Web Application
Creating a new [Link] Core
Project in Visual Studio
The different project templates
that are available and what they
do
18
[Link] Core Tutorial for Beginners
Part 4 - [Link] Core Project File
Bahaa Mohammad Rashed
19
[Link] Core Project File
.csproj or .vbproj depending on the
programming language used
No need to unload the project to edit the
project file
File or folder references are no longer included
in the project file
The File System determines what files and
folders belong to the project
20
[Link] Core Project File
TargetFramework
Specifies the target framework for the application
To specify a target framework we use Target
Framework Moniker (TFM)
Name Abbreviation TFM
.NET Framework net net451
net472
.NET Core netcoreapp netcoreapp1.0
netcoreapp2.2
netcoreapp3.1
net net5.0
21
net6.0
[Link] Core Project File
AspNetCoreHostingModel
Specifies how the application should be hosted
InProcess or OutOfProcess
InProcess hosts the app inside of the IIS worker
process ([Link])
OutOfProcess hosting model forward web requests
to a backend [Link] Core app running the Kestrel
server
The default is OutOfProcess hosting
22
[Link] Core Project File
PackageReference
Used to Include a reference to the NuGet
package that is installed for the application
Metapackage - [Link]
A metapackage has no content of its own
It just contains a list of dependencies (other
packages)
When the version is not specified, an implicit
version is specified by the SDK
Rely on the implicit version rather than
explicitly setting the version number on the
package reference
23
[Link] Core Tutorial for Beginners
Part 5 - Main method in [Link] Core
Bahaa Mohammad Rashed
24
Creating [Link] Core Web Application
Creating a new [Link] Core
Project in Visual Studio
The different project templates
that are available and what they
do
25
Main method in [Link] Core
A Console application usually has a Main()
method
Why do we have a Main() method in [Link]
Core Web application
[Link] Core application initially starts as a
Console application
Main() method configures [Link] Core and
starts it and at that point it becomes an
[Link] Core web application
26
[Link] Core Tutorial for Beginners
Part 6 - [Link] Core InProcess Hosting
Bahaa Mohammad Rashed
27
[Link] Core InProcess Hosting
Some of the Tasks that CreateDefaultBuilder()
performs
Setting up the web server
Loading the host and application configuration
from various configuration sources and
Configuring logging
An [Link] core application can be hosted
InProcess or
OutOfProcess
28
[Link] Core InProcess Hosting
To configure InProcess hosting
CreateDefaultBuilder() method calls UseIIS()
method and host the app inside of the IIS worker
process ([Link] or [Link])
InProcess hosting delivers significantly higher
request throughput than OutOfProcess hosting
To get the process name executing the app
29
[Link] Core InProcess Hosting
With out of process hosting
2 Web Servers - Internal and External Web
Server
The internal web server is Kestrel
The external web server can be IIS, Nginx or
Apache
What is Kestrel
Cross - Platform Web Server for [Link] Core
Kestrel can be used, by itself as an edge server
The process used to host the app is [Link]
Next Lesson
Out Of Process Hosting
30
[Link] Core Tutorial for Beginners
Part 7 - [Link] Core Out of Process Hosting
Bahaa Mohammad Rashed
31
[Link] Core InProcess Hosting
With InProcess hosting
Application is hosted inside the IIS worker
process
There is only one web server
From a performance standpoint, InProcess
hosting is better than OutOfProcess hosting
32
[Link] Core Out of Process Hosting
Kestrel can be used as the internet facing web
server
Kestrel can be used in combination with a
reverse proxy
33
In Process v/s Out of Process Hosting
In Process Out of Process
Process name is
Process name is
[Link] or
[Link]
[Link]
Only one web server Two web servers
Penalty of proxying
requests between
Better for performance
internal and external web
server
34
[Link] Core Tutorial for
Beginners
Part 8 - [Link] Core [Link] file
Bahaa Mohammad Rashed
35
[Link] Core
[Link] File
Internal Web External Web
commandName AspNetCoreHostingModel
Server Server
Project Hosting Setting Ignored Only one web server - Kestrel
IISExpress InProcess Only one web server - IIS Express
IISExpress OutOfProcess Kestrel IIS Express
IIS InProcess Only one web server - IIS
IIS OutOfProcess Kestrel IIS
36
[Link] Core Tutorial for Beginners
Part 9 - [Link] Core [Link] File
Bahaa Mohammad Rashed
37
[Link] Core [Link] File
Configurations Sources in [Link] Core
Files ([Link], appsettings.
{Environment}.json)
User secrets
Environment variables
Command-line arguments
To access configuration information
IConfiguration Service
38
[Link] Core Tutorial for
Beginners
Part 10 - Middleware in [Link] Core
Bahaa Mohammad Rashed
39
Middleware in [Link] Core
StaticFile
Logging MVC
s
Middleware in [Link] Core
Has access to both Request and Response
May simply pass the Request to next
Middleware
May process and then pass the Request to
next Middleware
May handle the Request and short-circuit the
pipeline
May process the outgoing Response
Middlewares are executed in the order they
are added
40
[Link] Core Tutorial for
Beginners
Part 11 - Configure [Link] Core Request Processing
Pipeline
Bahaa Mohammad Rashed
41
Configure Request Processing
Information
Pipeline Logged
MW1: Incoming
Request
MW2: Incoming
Request
MW3: Request
handled and
response produced
MW2: Outgoing
Response
MW1: Outgoing
Response
42
Configure Request Processing
Pipeline
Everything that happens before the next()
method is invoked in each of the middleware
components, happens as the REQUEST travels
from middleware to middleware through the
pipeline and this is represented by the
incoming arrow
43
Configure Request Processing
Pipeline
When a middleware handles the request and
produces response, the request processing
pipeline starts to reverse
44
Configure Request Processing
Pipeline
Everything that happens after the next()
method is invoked in each of the middleware
components, happens as the RESPONSE travels
from middleware to middleware through the
pipeline and this is represented by the
outgoing arrow
45
[Link] Core Tutorial for
Beginners
Part 12 - Static Files in [Link] Core
Bahaa Mohammad Rashed
46
Static Files in [Link] Core
By default an [Link] Core application will not serve
static files
The default directory for static files is wwwroot
To serve static files UseStaticFiles() middleware is required
To serve a default file UseDefaultFiles() middleware is
required
The following are the default files
[Link]
[Link]
[Link]
[Link]
UseDefaultFiles() must be registered before UseStaticFiles()
UseFileServer combines the functionality of UseStaticFiles,
UseDefaultFiles and UseDirectoryBrowser middleware
47
[Link] Core Tutorial for
Beginners
Part 13 - [Link] Core Developer Exception Page
Bahaa Mohammad Rashed
48
[Link] Core Developer
Exception Page
To enable plug in UseDeveloperExceptionPage
Middleware in the pipeline
Must be plugged in the pipeline as early as possible
Contains Stack Trace, Query String, Cookies and HTTP
headers
For customizing use DeveloperExceptionPageOptions
object
49
[Link] Core Tutorial for
Beginners
Part 14 - [Link] Core Environment Variables
Bahaa Mohammad Rashed
50
Development Environments
Developm Productio
Staging
ent
ASPNETCORE_ENVIRONMENT n
variable sets the Runtime
Environment
On development machine we set it in [Link]
file
On Staging or Production server we set in the operating
system
Use IHostingEnvironment service to access the runtime
environment
Runtime environment defaults to Production if not set
explicitly
In addition to standard environments (Development,
Staging, Production), custom environments (UAT, QA etc)
are also supported
51