.NET and ASP.
NET Frameworks:
.NET Framework
.NET Framework is a Windows-only version of .NET for building any type of app that runs
on Windows.
.NET is a framework to develop software applications. It is designed and developed by
Microsoft and the first beta version released in 2000.
It is used to develop applications for web, Windows, phone. Moreover, it provides a broad
range of functionalities and support.
This framework contains a large number of class libraries known as Framework Class Library
(FCL). The software programs written in .NET are executed in the execution environment,
which is called CLR (Common Language Runtime). These are the core and essential parts of
the .NET framework.
This framework provides various services like memory management, networking, security,
memory management, and type-safety.
The .Net Framework supports more than 60 programming languages such as C#, F#, VB.NET,
J#, VC++, JScript.NET, APL, COBOL, Perl, Oberon, ML, Pascal, Eiffel, Smalltalk, Python, Cobra,
ADA, etc.
Following is the .NET framework Stack that shows the modules and components of the
Framework.
The .NET Framework is composed of four main components:
1. Common Language Runtime (CLR)
2. Framework Class Library (FCL),
3. Core Languages (WinForms, ASP.NET, and ADO.NET), and
4. Other Modules (WCF, WPF, WF, Card Space, LINQ, Entity Framework, Parallel LINQ,
Task Parallel Library, etc.)
Prepared By: Raju Poudel [Lecturer - MMC] 1
CLR (Common Language Runtime)
It is a program execution engine that loads and executes the program. It converts the program
into native code. It acts as an interface between the framework and operating system. It does
exception handling, memory management, and garbage collection. Moreover, it provides
security, type-safety, interoperability, and portablility. A list of CLR components are given
below:
FCL (Framework Class Library)
It is a standard library that is a collection of thousands of classes and used to build an
application. The BCL (Base Class Library) is the core of the FCL and provides basic
functionalities.
.NET Core Framework
.NET Core is a new version of .NET Framework, which is a free, open-source, general-
purpose development platform maintained by Microsoft. It is a cross-platform framework
that runs on Windows, macOS, and Linux operating systems.
.NET Core Framework can be used to build different types of applications such as mobile,
desktop, web, cloud, IoT, machine learning, microservices, game, etc.
.NET Core is written from scratch to make it modular, lightweight, fast, and cross-platform
Framework. It includes the core features that are required to run a basic .NET Core app. Other
Prepared By: Raju Poudel [Lecturer - MMC] 2
features are provided as NuGet packages, which you can add it in your application as needed.
In this way, the .NET Core application speed up the performance, reduce the memory
footprint and becomes easy to maintain.
The .NET Core Framework composed of the following parts:
• CLI Tools: A set of tooling for development and deployment.
• Roslyn: Language compiler for C# and Visual Basic
• CoreFX: Set of framework libraries.
• CoreCLR: A JIT based CLR (Command Language Runtime).
.NET Core Characteristics
1. Open-source Framework: .NET Core is an open-source framework maintained by
Microsoft.
2. Cross-platform: .NET Core runs on Windows, macOS, and Linux operating systems.
There are different runtime for each operating system that executes the code and
generates the same output.
3. Consistent across Architectures: Execute the code with the same behavior in different
instruction set architectures, including x64, x86, and ARM.
4. Wide-range of Applications: Various types of applications can be developed and run
on .NET Core platform such as mobile, desktop, web, cloud, IoT, machine learning,
microservices, game, etc.
5. Supports Multiple Languages: You can use C#, F#, and Visual Basic programming
languages to develop .NET Core applications. You can use your favorite IDE, including
Visual Studio 2017/2019, Visual Studio Code, Sublime Text, Vim, etc.
6. Modular Architecture: .NET Core supports modular architecture approach using
NuGet packages. There are different NuGet packages for various features that can be
added to the .NET Core project as needed. Even the .NET Core library is provided as a
NuGet package. The NuGet package for the default .NET Core application model is
Prepared By: Raju Poudel [Lecturer - MMC] 3
Microsoft.NETCore.App.This way, it reduces the memory footprint, speeds up the
performance, and easy to maintain.
7. CLI Tools: .NET Core includes CLI tools (Command-line interface) for development and
continuous-integration.
8. Flexible Deployment: .NET Core application can be deployed user-wide or system-
wide or with Docker Containers.
9. Compatibility: Compatible with .NET Framework and Mono APIs by using .NET
Standard specification.
Why .NET Core?
There are some limitations with the .NET Framework. For example, it only runs on the
Windows platform. Also, you need to use different .NET APIs for different Windows devices
such as Windows Desktop, Windows Store, Windows Phone, and Web applications. In
addition to this, the .NET Framework is a machine-wide framework. Any changes made to it
affect all applications taking a dependency on it. Learn more about the motivation behind
.NET Core here.
Today, it's common to have an application that runs across devices; a backend on the web
server, admin front-end on windows desktop, web, and mobile apps for consumers. So, there
is a need for a single framework that works everywhere. So, considering this, Microsoft
created .NET Core. The main objective of .NET Core is to make .NET Framework open-source,
cross-platform compatible that can be used in a wide variety of verticals, from the data center
to touch-based devices.
.NET Core Version History
Version Latest Version Visual Studio Release Date End of Support
.NET 5 Preview 1 VS 2019 16th March, 2020
.NET Core 3.x - latest 3.1.3 VS 209 24th March, 2020 12th March, 2022
.NET Core 2.x 2.1.17 VS 2017, 2019 24th March, 2020 21st August, 2021
.NET Core 1.x 1.1.13 VS 2017 14th May, 2019 27th May, 2019
Mono Framework
Mono is a free and open-source .NET Framework-compatible software framework.
Mono, the open-source development platform based on the .NET Framework, allows
developers to build cross-platform applications with improved developer productivity.
Mono’s .NET implementation is based on the ECMA standards for C# and the Common
Language Infrastructure.
Supported previously by Novell, Xamarin and now Microsoft and the .NET Foundation, the
Mono project has an active and enthusiastic contributing community. Mono includes both
developer tools and the infrastructure needed to run .NET client and server applications.
Prepared By: Raju Poudel [Lecturer - MMC] 4
There are several components that make up Mono:
• C# Compiler - Mono’s C# compiler is feature complete for C# 1.0, 2.0, 3.0, 4.0, 5.0 and
6.0 (ECMA). A good description of the feature of the various versions is available on
Wikipedia.
• Mono Runtime - The runtime implements the ECMA Common Language
Infrastructure (CLI). The runtime provides a Just-in-Time (JIT) compiler, an Ahead-of-
Time compiler (AOT), a library loader, the garbage collector, a threading system and
interoperability functionality.
• .NET Framework Class Library - The Mono platform provides a comprehensive set of
classes that provide a solid foundation to build applications on. These classes are
compatible with Microsoft’s .NET Framework classes.
• Mono Class Library - Mono also provides many classes that go above and beyond the
Base Class Library provided by Microsoft. These provide additional functionality that
are useful, especially in building Linux applications. Some examples are classes for
Gtk+, Zip files, LDAP, OpenGL, Cairo, POSIX, etc.
Prepared By: Raju Poudel [Lecturer - MMC] 5
ASP.NET Web Framework
ASP.NET is a free web framework for building great websites and web applications using
HTML, CSS, and JavaScript. You can also create Web APIs and use real-time technologies like
Web Sockets.
ASP.NET Core is an alternative to ASP.NET.
ASP.NET offers three frameworks for creating web applications: Web Forms, ASP.NET MVC,
and ASP.NET Web Pages. All three frameworks are stable and mature, and you can create
great web applications with any of them. No matter what framework you choose, you will
get all the benefits and features of ASP.NET everywhere.
Framework Development style
Web Forms Rapid development using a rich library of controls that encapsulate HTML
markup
MVC Full control over HTML markup, code and markup separated, and easy to write
tests. The best choice for mobile and single-page applications (SPA).
Web Pages HTML markup and your code together in the same file
ASP.NET Web Forms
Web Forms are web pages built on the ASP.NET Technology. It executes on the server and
generates output to the browser. It is compatible to any browser to any language supported
by .NET common language runtime. It is flexible and allows us to create and add custom
controls.
We can use Visual Studio to create ASP.NET Web Forms. It is an IDE (Integrated Development
Environment) that allows us to drag and drop server controls to the web forms. It also allows
us to set properties, events and methods for the controls. To write business logic, we can
choose any .NET language like: Visual Basic or Visual C#.
Web Forms are made up of two components: the visual portion (the ASPX file), and the
code behind the form, which resides in a separate class file.
Fig: Components of ASP.NET
The main purpose of Web Forms is to overcome the limitations of ASP and separate view
from the application logic.
Prepared By: Raju Poudel [Lecturer - MMC] 6
ASP.NET MVC
ASP.NET MVC is basically a web development framework from Microsoft, which combines
the features of MVC (Model-View-Controller) architecture, the most up-to-date ideas and
techniques from Agile development, and the best parts of the existing ASP.NET platform.
ASP.NET MVC is not something, which is built from ground zero. It is a complete alternative
to traditional ASP.NET Web Forms. It is built on the top of ASP.NET, so developers enjoy
almost all the ASP.NET features while building the MVC application.
MVC Architecture
MVC stands for Model, View, and Controller. MVC separates an application into three
components - Model, View, and Controller.
• Model: Model represents the shape of the data. A class in C# is used to describe a
model. Model objects store data retrieved from the database.
Model represents the data.
• View: View in MVC is a user interface. View display model data to the user and also
enables them to modify them. View in ASP.NET MVC is HTML, CSS, and some special
syntax (Razor syntax) that makes it easy to communicate with the model and the
controller.
View is the User Interface.
• Controller: The controller handles the user request. Typically, the user uses the view
and raises an HTTP request, which will be handled by the controller. The controller
processes the request and returns the appropriate view as a response.
Controller is the request handler.
Prepared By: Raju Poudel [Lecturer - MMC] 7
Advantages of ASP.NET MVC Framework
• It manages application complexity by dividing an application into the model, view
and controller.
• It does not use view state or server-based forms. This makes the MVC framework
ideal for developers who want full control over the behavior of an application.
• It provides better support for test-driven development.
• It is suitable for large scale developer team and web applications.
• It provides high degree of control to the developer over the application behavior.
ASP.NET Web API
ASP.NET Web API is a framework for building HTTP services that can be accessed from any
client including browsers and mobile devices.
It is an extensible framework for building HTTP based services that can be accessed in
different applications on different platforms such as web, windows, mobile etc. It works
more or less the same way as ASP.NET MVC web application except that it sends data as a
response instead of html view. It is like a webservice or WCF service but the exception is that
it only supports HTTP protocol.
ASP.NET Core
ASP.NET Core is the new version of the ASP.NET web framework mainly targeted to run on
.NET Core platform.
ASP.NET Core is a free, open-source, and cross-platform framework for building cloud-
based applications, such as web apps, IoT apps, and mobile backends. It is designed to run
on the cloud as well as on-premises.
Same as .NET Core, it was architected modular with minimum overhead, and then other more
advanced features can be added as NuGet packages as per application requirement. This
results in high performance, require less memory, less deployment size, and easy to maintain.
Prepared By: Raju Poudel [Lecturer - MMC] 8
ASP.NET Core is an open source framework supported by Microsoft and the community, so
you can also contribute or download the source code from the ASP.NET Core Repository on
Github.
ASP.NET 3.x runs only on .NET Core 3.x, whereas ASP.NET Core 2.x runs on .NET Core 2.x as
well as .NET Framework.
.NET Core vs ASP.NET Core
.NET Core ASP.NET Core
Open-source and Cross-platform Open-source and Cross-platform
.NET Core is a runtime to execute ASP.NET Core is a web framework to build web apps,
applications build on it. IoT apps, and mobile backends on the top of .NET
Core or .NET Framework.
Install .NET Core Runtime to run There is no separate runtime and SDK are available
applications and install .NET Core SDK to for ASP.NET Core. .NET Core runtime and SDK
build applications. includes ASP.NET Core libraries.
Benefits of ASP.NET Core
• Supports Multiple Platforms: ASP.NET Core applications can run on Windows, Linux,
and Mac. So you don't need to build different apps for different platforms using
different frameworks.
• Fast: ASP.NET Core no longer depends on System.Web.dll for browser-server
communication. ASP.NET Core allows us to include packages that we need for our
application. This reduces the request pipeline and improves performance and
scalability.
• IoC Container: It includes the built-in IoC container for automatic dependency
injection which makes it maintainable and testable.
• Integration with Modern UI Frameworks: It allows you to use and manage modern UI
frameworks such as AngularJS, ReactJS, Umber, Bootstrap, etc. using Bower (a
package manager for the web).
• Hosting: ASP.NET Core web application can be hosted on multiple platforms with any
web server such as IIS, Apache etc. It is not dependent only on IIS as a standard .NET
Framework.
Prepared By: Raju Poudel [Lecturer - MMC] 9
• Code Sharing: It allows you to build a class library that can be used with other .NET
frameworks such as .NET Framework 4.x or Mono. Thus a single code base can be
shared across frameworks.
• Side-by-Side App Versioning: ASP.NET Core runs on .NET Core, which supports the
simultaneous running of multiple versions of applications.
• Smaller Deployment Footprint: ASP.NET Core application runs on .NET Core, which is
smaller than the full .NET Framework. So, the application which uses only a part of
.NET CoreFX will have a smaller deployment size. This reduces the deployment
footprint.
.Net Architecture
The basic architecture of the .Net framework is as shown below.
(Description of these components are already discussed.)
.Net Framework Design Principle
The following design principles of the .Net framework is what makes it very relevant to create
.Net based applications.
1) Interoperability – The .Net framework provides a lot of backward support. Suppose if you
had an application built on an older version of the .Net framework, say 2.0. And if you tried
to run the same application on a machine which had the higher version of the .Net framework,
say 3.5. The application would still work. This is because with every release, Microsoft ensures
that older framework versions gel well with the latest version.
2) Portability – Applications built on the .Net framework can be made to work on any
Windows platform. And now in recent times, Microsoft is also envisioning to make Microsoft
products work on other platforms, such as iOS and Linux.
Prepared By: Raju Poudel [Lecturer - MMC] 10
3) Security – The .NET Framework has a good security mechanism. The inbuilt security
mechanism helps in both validation and verification of applications. Every application can
explicitly define their security mechanism. Each security mechanism is used to grant the user
access to the code or to the running program.
4) Memory management – The Common Language runtime does all the work or memory
management. The .Net framework has all the capability to see those resources, which are not
used by a running program. It would then release those resources accordingly. This is done
via a program called the “Garbage Collector” which runs as part of the .Net framework. The
garbage collector runs at regular intervals and keeps on checking which system resources are
not utilized, and frees them accordingly.
5) Simplified deployment – The .Net framework also have tools, which can be used to
package applications built on the .Net framework. These packages can then be distributed to
client machines. The packages would then automatically install the application.
Compilation and Execution of .NET Applications:
Compiler time process
1. The .Net framework has one or more language compilers, such as Visual Basic, C#,
Visual C++, JScript, or one of many third-party compilers such as an Eiffel, Perl, or
COBOL compiler.
2. Anyone of the compilers translates your source code into Microsoft Intermediate
Language (MSIL) code.
Prepared By: Raju Poudel [Lecturer - MMC] 11
3. For example, if you are using the C# programming language to develop an application,
when you compile the application, the C# language compiler will convert your source
code into Microsoft Intermediate Language (MSIL) code.
4. In short, VB.NET, C#, and other language compilers generate MSIL code. (In other
words, compiling translates your source code into MSIL and generates the required
metadata.)
5. Currently "Microsoft Intermediate Language" (MSIL) code is also known as the
"Intermediate Language" (IL) Code or "Common Intermediate Language" (CIL) Code.
SOURCE CODE -----.NET COMLIPER------> BYTE CODE (MSIL + META DATA)
Runtime process.
1. The Common Language Runtime (CLR) includes a JIT compiler for converting MSIL to
native code.
2. The JIT Compiler in CLR converts the MSIL code into native machine code that is then
executed by the OS.
3. During the runtime of a program, the "Just in Time" (JIT) compiler of the Common
Language Runtime (CLR) uses the Metadata and converts Microsoft Intermediate
Language (MSIL) into native code.
BYTE CODE (MSIL + META DATA) ----- Just-In-Time (JIT) compiler------> NATIVE CODE
.Net Core CLI Overview
The .NET command-line interface (CLI) is a cross-platform toolchain for developing,
building, running, and publishing .NET applications.
The .NET Core CLI is installed with .NET Core SDK for selected platforms. So we don't need
to install it separately on the development machine. We can verify whether the CLI is installed
properly by opening command prompt in Windows and writing dotnet and pressing Enter. If
it displays usage and help as shown below then it means it is installed properly.
Prepared By: Raju Poudel [Lecturer - MMC] 12
Command Structure
The following is a command structure.
dotnet <command> <argument> <option>
All the commands start with driver named dotnet. The driver starts the execution of the
specified command. After dotnet, we can supply command (also known as verb) to perform
a specific action. Each command can be followed by arguments and options. The following
are .NET Core 2.x CLI commands.
Basic Commands Description
new Creates a new project, configuration file, or solution based on the
specified template.
restore Restores the dependencies and tools of a project.
build Builds a project and all of its dependencies.
Run Runs source code without any explicit compile or launch commands.
publish Packs the application and its dependencies into a folder for deployment
to a hosting system.
test Executes unit tests.
vtest Runs tests from the specified files.
pack Packs the code into a NuGet package.
clean Cleans the output of a project.
sln Modifies a .NET Core solution file.
help Display help on the specified command
store Stores the specified assemblies in the runtime package store.
Project Modification Commands Description
add package Adds a package reference to a project.
add reference Adds project-to-project (P2P) references.
remove package Removes package reference from the project.
remove reference Removes project reference
list reference Lists all project-to-project references
Advanced Commands Description
nuget delete Deletes or unlists a package from the server.
nuget locals Clears or lists local NuGet resources.
nuget push Pushes a package to the server and publishes it.
msbuild Builds a project and all of its dependencies.
dotnet install script Script used to install the .NET Core CLI tools and the shared runtime.
Let's create, restore, build, and run .NET Core console application using command-line
interface without using Visual Studio.
Prepared By: Raju Poudel [Lecturer - MMC] 13
Create a New Project
The following creates new console project in the current directory with the same name as
current directory.
dotnet new console
The following command creates a new console project named MyConsoleApp. The -n or --
name option species the name of a project.
dotnet new console -n MyConsoleApp
The following command creates a new console application named MyConsoleApp to
MyProjects directory. The -o or --output option is used to specify an output directory where
the project should be generated.
dotnet new console -n MyConsoleApp -o C:\MyProjects
After creating a project, navigate to the project directories in command prompt to apply
project specific commands which is C:\MyConsoleApp in our case.
Add Package Reference
We often need to add NuGet package reference for different purposes. For example, apply
the following command to add Newtonsoft.json package to our console project.
C:\MyConsoleApp>dotnet add package Newtonsoft.json
This will add Newtonsoft.json package to our project. We can verify it by opening .csproj file.
Restore Packages
To restore packages or to update existing packages, we can use restore command as below.
C:\MyConsoleApp>dotnet restore
Build Project
To build a new or existing project, apply C:\MyConsoleApp>dotnet build command.
Run project
To run our console project, apply dotnet run command as shown below.
As you can see below, it displays an output "Hello World!".
Prepared By: Raju Poudel [Lecturer - MMC] 14