L1 Introduction To ASP - NET MVC
L1 Introduction To ASP - NET MVC
and Development
L1: Introduction to ASP.NET
Dr. Abdullah Bokir
Overview of ASP.NET Core
• ASP.NET Core is Microsoft’s web development platform. The original
ASP.NET was introduced in 2002.
One of the greatest values we get from using the MVC pattern is
separation of concerns. The MVC pattern separates a web
application into three components: the models, the views, and the
controllers.
Model-View-Controller (MVC)
The models
are the classes that represent the various types of objects
managed by the web application. For example (think about a web
application such as Amazon, Udemy) we could have the following
model classes: Course, User, Student, Instructor, Administrator,
Product, Seller, Buyer, and so on. These are the typical C# classes .
(these files will have extension .cs).
Model-View-Controller (MVC)
The views
will make up the user interface. We’ll present content to users via
views (more accurately, we’ll use views to build webpages that
ultimately will get displayed in a user’s browser) For example (think
about a web application such as Amazon, Udemy), we can have a
view that will be used to display a list of all courses taken by a
student, or a list of all laptops available to purchase. We could use
another view to build a page that allows our users to change their
password, and yet another view to add a new laptop to sell it
online. These are files that will combine HTML and CSS with C#
(these files will have extension .cshtml).
Model-View-Controller (MVC)
The controllers
will handle the user interaction. For example (think about a web
application such as Amazon, Udemy, …). What happens when you
click on a button? Or click on a link? Or load the first welcome
page? In each of these, your requests will (eventually) be sent to a
Controller (more specifically to an Action from that Controller). In
many cases, the Controller will create an instance of a Model, then
pass it to a View to build a page that will eventually show up in the
user’s browser. These are C# classes derived from the
Microsoft.AspNetCore.Mvc.Controller class (these files will have
extension .cs).
Model-View-Controller (MVC)
Introduction to Web API
The only one advantage that a Monolithic system has is the fact
that we can run the entire code base on one machine, so, when
developing and testing, we could probably replicate the entire
environment on a machine.
Introduction to Web API
Overheads of Monolithic architecture
• Since the code is in one large package, we might also have high
levels of coupling, which means that if a change is made in one
part of the system, it might affect another part of the system
• Unit testing for such a large code base takes time, and regression
testing by QA is also a time-consuming process.
The only one advantage that a Monolithic system has is the fact
that we can run the entire code base on one machine, so, when
developing and testing, we could probably replicate the entire
environment on a machine.
Introduction to Web API
Microservices
The Microservices architecture is, basically, service-oriented
architecture done well.
2- SEO
To index your SPA app, search engine crawlers should be able to
execute JavaScript. Only recently, Google and Bing started indexing
Ajax-based pages by executing JavaScript during crawling.
Cons of Single Page Application (SPA)
3- Initial Load is Slow
SPA needs to download more resources when you open it.
Step 2: Then, in the Create a new project window, enter the word
MVC in the search bar, then select ASP .NET Core Web App (Model-
View-Controller), and click the Next button.
Step 3: choose a name and location for your project, then click on
the Next button.
Model-View-Controller (MVC)
Create an ASP .Net Core MVC web application
Step 4: in the Additional information window, you can choose
a .Net framework to work with. we’ll go with .Net 6.0 (Long Term
Support). Also, uncheck the Configure for HTTPS. We won’t use it in
this example. Then click on the Create button.
Once the new project is ready to run, either press Ctrl + F5, or go
to Debug > Start Without Debugging, or click on the light green
play button located around the center of the top menu options.
This will start, in a browser, your newly created ASP .Net Core MVC
web application (note the URL: localhost:5096).
Model-View-Controller (MVC)
Create an ASP .Net Core MVC web application
Solution explorer
check out the Solution Explorer window. There are several files and
folders showing up in there. In particular, you should note the
following:
- We have separate folders for Models, Views, and
Controllers.
- There is a (special) folder, called wwwroot, and it contain
JavaScript, CSS, and other files.
- There is a Program.cs.
Model-View-Controller (MVC)
Solution explorer
launchSettings.json
When you run the application, it opened in a browser window. In
our example, it opened up with the URL: (localhost:5096). If you
have multiple browsers installed on your machine, you can open
the same URL from multiple browsers. If you open the
launchSettings.json file, you will see that the value (port number)
5097 was set in that file. You can change that value to another
number, let’s say 5096. If you rerun your application, the new value
will be used for your web application.
Model-View-Controller (MVC)
Solution explorer
site.css
If you open the site.css file found under wwwroot > css: you should
find very familiar code (CSS styling).
add the following line:
background-color:lightblue;
Then, either rerun the application.
Model-View-Controller (MVC)
Solution explorer
Layout.cshtml