Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

ASP.

NET Core
ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern,
cloud-based, Internet-connected applications. The latest version right now is ASP.NET Core 6.0 and is
based on .NET 6.0.

ASP.NET Core vs .NET Core


The differences between ASP.NET Core and .NET Core are as follows:

ASP.NET Core .NET Core

ASP.NET Core is a collection of libraries that builds a web


framework. This framework is used to create websites and
web apps including mobile apps and IoT apps.

ASP.NET Core 1.x-2.x – ASP.NET Core can be used on


both .NET Core and the .NET Framework. This also means
that an ASP.NET Core application is also a .NET Core .NET Core is a runtime which execute the
application or a .NET Framework application. applications that are built for it.

ASP.NET Core 3.x – depends on .NET Core and can no longer


be used on .NET Framework.

ASP.NET Core 5.x – based on .NET 5 and it supports more


types of apps and more platforms than .NET Core.

Both are Open-source and Cross-platform. Works on Windows, Linux and macOS.

You will require to Install .NET Core SDK to


.NET Core runtime and SDK includes ASP.NET Core libraries.
build applications and .NET Core Runtime
Noting more that this is required.
to run applications.

From .NET 5.0, the word “Core” is dropped


ASP.NET Core 5.0 which was released on November 2020 is
from its name. So, all frameworks from
based on .NET 5.0 framework but retains the name “Core” to
now on will be named as .NET 6, .NET 7
avoid confusion with ASP.NET MVC 5.0.
and so on.

ASP.NET Core provides the following benefits:

 A unified approach for building web UI and web APIs which is Architected for testability.

 Razor Pages makes coding page-focused scenarios easier and more productive.

 Platform Independent i.e., ability to develop and run-on Windows, macOS, and Linux.

 Integration of modern, client-side frameworks like React, Angular, jQuery, Bootstrap & Vue.js


 A cloud-ready, environment-based configuration system.

 Built-in dependency injection for making loosely coupled designs.

 A lightweight, high-performance, and modular HTTP request pipeline.

 Ability to host on IIS, Nginx, Apache, Docker, or self-host in your own process.


Introduction to ASP.NET Core MVC

ASP.NET Core MVC is Microsoft’s Web Application development framework that is in great demand
today. It is based on Model-View-Controller (MVC) architecture, ideas and techniques from Agile
Development, and the best parts of .NET platform.

History of ASP.NET Core


Microsoft released ASP.NET Core MVC during the latter half of 2015. Over the past years they have
added new features to this framework making it more powerful. The current version of this platform as
on today is .NET 6.0 version.

Before ASP.NET Core, Microsoft already had 2 other similar frameworks, these were – ASP.NET Web
Forms (popularly known as just ASP.NET) and ASP.NET MVC. Let us discuss how ASP.NET Core is
different from them.

ASP.NET Core vs ASP.NET


ASP.NET Core ASP.NET

ASP.NET Core was released in the year 2016 and is based ASP.NET Web Forms known as just
on .NET Core framework (now known as just .NET). Latest “ASP.NET” is a web application framework
version right now is .NET 6.0 which was released in released way back in 2002. It is based
November 2021. on .NET Framework.

ASP.NET Core apps are Cross-platform i.e., run on


ASP.NET apps run only on Windows.
Windows, Linux and macOS.

ASP.NET Core apps can be hosted with several web ASP.NET Web Forms apps can only be hosted
servers like IIS, Kestrel, Nginx, and Apache. with IIS.

Apps are heavy and runs slowly compared to


Apps are scalable, lightweight, and run very fast. ASP.NET Core apps. Scaling is a big problem
for apps build on ASP.NET Web Forms.

In-built dependency injection feature. No in-built dependency injection feature.

ASP.NET Core vs ASP.NET MVC


ASP.NET Core ASP.NET MVC

ASP.NET Core is based on .NET Core ASP.NET MVC is based on .NET Framework. It’s first version
framework (now known as just .NET). First came in 2007 while the last version which is ASP.NET MVC
released during 2015. 5.0 came in 2016. MVC 6 was abandoned due to .NET Core.

ASP.NET Core apps are Cross-platform and


ASP.NET MVC apps runs only on Windows and uses IIS for
can be hosted on several web servers like
hosting.
IIS, Kestrel, Nginx, and Apache.
ASP.NET Core ASP.NET MVC

ASP.NET Core has several features like


ASP.NET MVC is not as advanced compared to ASP.NET Core.
Dependency Injection and Middleware.
Apps have a greater number of files in them.
Apps have a smaller number of files.

Apps can be build using MVC architecture


App can be build using only MVC architecture.
and Razor Pages.

Apps are light weight. Apps are relatively heavy compared to ASP.NET Core apps.

Features of ASP.NET Core MVC


This framework is bundled with some of the most amazing feature. These are:

It is Opensource
You are free to download this framework’s source code from https://github.com/aspnet and even
modify and compile your own version of it.

Cross-Platform
ASP.NET Core MVC is cross-platform both for development & deployment. It is available for all
operating systems – Windows, Linux & macOS.

You can do development works in ASP.NET Core MVC using Visual Studio editor by Microsoft. Visual
Studio works only on Windows & macOS.

For Linux, use Visual Studio Code editor.

Full Control over HTML & HTTP


In ASP.NET Core MVC you get full control over HTML. You can create, simple to complex type, HTML
styled with CSS and display them on the browser.

Similarly, you get full control over HTTP requests passed between the browser and server. Creating AJAX
request is also very easy.

You can easily use client-side libraries like jQuery, Angular, React & Bootstrap with ASP.NET Core MVC.

Extensible Framework
ASP.NET Core MVC is highly extensible. You can make applications that can be extended to any levels in
future. Key features of this framework that gives it the extensible power are:

1. View Components
2. Tag Helpers
3. Routing

Testing made Maintainability


The ASP.NET Core MVC architecture is great for making your application maintainable and testable. You
can separate, different areas of your application, into independent pieces and test them independently.
Testing frameworks like xUnit & MOQ can be easily integrated for simulating any scenario.
ASP.NET Core MVC makes large to very large applications easy for maintaining.

Routing
ASP.NET Core MVC “Routing” makes SEO friendly URL which are easy to make and can be controlled
from a single place. This removes the probability of error.

You don’t have to hard core the URL, instead the Routing will make it for you based on the structure
which you have set.

Example of a SEO friendly URL is:

1 /women-clothing/skirts/

API
ASP.NET Core MVC APIs can take full advantage of language and runtime innovations familiar to C#
programmers, like the await keyword, extension methods, lambda expressions, anonymous and
dynamic types, and Language Integrated Query (LINQ).

Installing Visual Studio


The codes on this document require installation of Visual Studio 2022 Community Edition on your PC. It
requires Windows 10 or higher version. It can also be installed on macOS.

For Linux systems install Visual Studio Code.


What is MVC Architecture
Model View Controller (MVC) is a software architecture for developing applications. It has 3 pieces:

 Model – It contains the data for the application to work with. This data is provided to the Model
from the database or any other repository.

 View – It forms the User Interface (UI) and is rendered on the browser. Views contains HTML
layouts which the user sees on the browser

 Controller – Controller is the brain of the MVC application. It processes the incoming request to
the application, performs operations like data filling, data update, data delete, data inserts, etc.,
and finally renders an appropriate View to the browser based on the request.

Check the below image of MVC architecture.


There can be multiple Models, Controllers and Views in a MVC application.

MVC Models
Taking an example of a social community website like Facebook, a Model will contain all your details like
– your name, ages, status, work info, your posts by date, your comments done on other profiles, your
messages to other people, your liked pages and so on.

These details (your data) are filled on the Model by the Controller.

Models also help in preserving the business logic of the application (here for Facebook). For example,
when running paid ads in Facebook, Models will not allow you to add invalid amounts on the ads.
Example – ‘some amount’, ‘thirty’, ‘hello’ etc. It will also only proper amounts like ‘$10’,’£20.50’, ‘$100’,
etc.

Models communicate with only Controllers and not with Views.

MVC Views
Views are the User Interface (UI) in MVC and are rendered on the browser. They can contain static
HTML or dynamic HTML sent by the Controller. Views communicate only with the Controllers and not
with Models.

Controller is responsible for rendering a particular View based on the request it gets from the browser.

MVC Controllers
Controller is the main thing in MVC. It sits between the View and the Model and communicates with
them. All HTTP requests are received by the Controller, which after processing it, fills the data on the
Model and sends the data on the View. The View is then rendered on the browser.
Controller contains simple to complex logic based on the working of the application.

First ASP.NET Core 6.0 MVC Application

Create ASP.NET Core 6.0 app in Visual Studio 2022


Open Visual Studio 2022, then select Create a new project under the Get started section or select New,
Project under the File menu.

This will open Create a new project window. Now here select the template called ASP.NET Core Web
App (Model-View-Controller), and then click the “Next” button.
What should I learn before learning ASP.NET Core
Before you start learning ASP.NET Core, you should have a basic knowledge of HTML CSS and C#. HTML
and CSS are used in the Views which forms the UI component of ASP.NET Core MVC. C# is a
programming language to create code logics like communicating with database, searching for a value in
the data, and so on.

Is ASP.NET Core good for my Career? ASP.NET Core is currently in the top 3 – “most demanding
programming technology”. It is a product of Microsoft who entered way back in 2002 with .NET
framework. Twenty years have already passed, so it is a surety that this technology which remain for a
very-very long time. Entry level ASP.NET Core developers are always in good demand and get starting
yearly salaries of around $50k in United States alone. In India the starting salaries are around 4 to 5
lakhs per annum.

Configure your new project in Visual Studio 2022


Add the name of the project as FirstApp and select the location on your drive where you want this
application to be created.
Click the Next button to continue. You will reach an Additional Information page where you must select
the framework and authentication.
Ensure that .NET 6.0 framework is selected, and authentication is set to None. Option of Docker should
also be un-checked.

Finally click the Create button to create your application.

Here you have chosen the Model-View-Controller (MVC) Template, so the necessary MVC folders and
files are automatically created by Visual Studio. You can open the Solution Explorer from View ➤
Solution Explorer menu, it will be added on the right corner of Visual Studio and will show all these
files/folders in the newly created app. Had you chosen the other option, which is the ‘Empty’ template
one, then you must create these MVC files and folders one-by-one from the file menu.
MVC files and folders
These are files and folders in your application.

 wwwroot – contains the static files like images, scripts, external frameworks and libraries like
Bootstrap, jQuery.

 Controllers – This folder contains the controller files.

 Models – This folder contains the model files.

 Views – This folder contains the view files.

 appsettings.json – This file contains configuration settings of the application. You can use it to
store database connection string, application variable values and other informations.

 program.cs – It is your application’s entry point which starts when you run your application.
Here you create your application host, choose the web server, add services, authorization, and
authentications.

 startup.cs – Note – DOT NET 6.0 does not have startup.cs. If you are using earlier versions
of .NET only then you need to have this file in your app. The startup.cs is called from
the program.cs file. Here you add services and configure the HTTP pipeline. You also write URL
Routes in this file.

You might also like