3 Http And Asp Net Core

NET Centric Computing · Unit 3 · 3 hrs

HTTP and ASP.NET Core

Exam-focused notes for HTTP and ASP.NET Core (NET Centric Computing, CSC378): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.

HTTP and ASP.NET Core in short

This unit moves from the language to the web: how an HTTP request and response actually travel between a browser and a server, how ASP.NET Core processes a request internally, the shapes a web application's architecture can take, and how the Model-View-Controller pattern organizes an ASP.NET Core application.

HTTP and ASP.NET Core: notes

HTTP: Request and Response Message Format

To talk to a web server, a client makes calls over the network using HTTP: it sends an HTTP request for a resource, and the server replies with an HTTP response. A typical page load runs through five steps: the user requests a page by URL, the browser sends an HTTP request to the server, the server interprets the request and generates the appropriate HTML, the server sends that HTML back inside an HTTP response, and the browser renders it on the page. Once the server has the request, it checks whether the request makes sense and, if so, generates a response, which could be a web page, an image, a script file, or a simple acknowledgment; the browser can start rendering as soon as the response starts arriving, and the resulting page may reference further resources that trigger further requests.

An HTTP request message is made up of a request line (the HTTP method, the target URL, and the HTTP version), a set of headers, and an optional body. An HTTP response message mirrors this shape: a status line (the HTTP version, a numeric status code, and a reason phrase), headers, and an optional body.

ASP.NET Core processes a request through a longer pipeline than "browser talks to server". A request first reaches a reverse proxy (IIS, NGINX, or Apache), which forwards it to the ASP.NET Core web server; that server (Kestrel) receives the request and passes it into the application's middleware pipeline, which is the application's own request-processing logic; once the application has produced a response, it flows back out through the middleware, back to the web server, back to the reverse proxy, and finally to the browser.

What this unit covers

  • HTTP
  • Request and Response Message Format
  • Common web application architectures
  • MVC Pattern
  • ASP.NET Core Architecture Overview, Projects, and Conventions
  • ASP.NET and ASP.NET MVC

MVC Pattern

2080 · 5 marks

Describe the importance of MVC pattern in designing web applications. [5]

MVC (Model-View-Controller) is an architectural pattern that separates an application into three distinct components: Model, View, and Controller. This separation is fundamental to building well-structured, maintainable web applications. --- - Represents the shape of the data in the application. ...

Open this answer on its own page →

2079 · 5 marks

Define HTTP. Explain the MVC pattern. [5]

Show solved answer

HTTP and MVC Pattern


Part 1: HTTP (HyperText Transfer Protocol)

HTTP stands for HyperText Transfer Protocol. It is the foundation protocol of data communication on the World Wide Web. HTTP defines how messages are formatted and transmitted between a client (such as a web browser) and a server, and what actions web servers and browsers should take in response to various commands.

Key characteristics of HTTP:

  • It is a request-response protocol: the client sends an HTTP request and the server returns an HTTP response.
  • It is stateless: each request is independent and the server does not retain session information between requests.
  • It operates over TCP/IP and commonly uses port 80 (HTTP) or port 443 (HTTPS).
  • Common HTTP methods include: GET, POST, PUT, DELETE, PATCH.

ASP.NET Web API is "a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices", confirming HTTP as the core communication protocol for web-based services.


Part 2: MVC Pattern

MVC stands for Model, View, and Controller. It is an architectural/design pattern that separates an application into three main components, making the application easier to develop, test, and maintain.


Components of MVC

1. 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.
  • In short: Model represents the data.
public class Student
{
    public int Id { get; set; }
    public string Name { get; set; }
}

2. View

  • A View in MVC is the user interface (UI).
  • It displays model data to the user and also enables them to modify it.
  • In ASP.NET MVC, View is written using HTML, CSS, and special Razor syntax that makes it easy to communicate with the Model and Controller.

3. Controller

  • The Controller handles the user request.
  • Typically, the user interacts with the View, which raises an HTTP request.
  • The Controller acts as the request handler -- it processes the request, manipulates the Model, and returns the appropriate response/View.

MVC Flow Diagram

User
  |
  v
[View] ---Send Request---> [Controller] ---Manipulate---> [Model]
  ^                              |                            |
  |                              |                            |
  +--------Renders/Display<------+----------------------------+

Step-by-step flow:

  1. The user sends a request through the View (browser).
  2. The Controller receives and processes the HTTP request.
  3. The Controller interacts with the Model to retrieve or update data.
  4. The updated Model data is passed back to the View.
  5. The View renders and displays the result to the user.

Advantages of MVC Pattern

FeatureBenefit
Separation of ConcernsEach component has a distinct responsibility
TestabilityComponents can be tested independently
MaintainabilityEasy to modify one component without affecting others
ReusabilityModels and Views can be reused

As stated in the notes: "ASP.NET MVC gives us a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and that gives us full control over markup for enjoyable, agile development."

Open this answer on its own page →

Request and Response Message Format

2078 · 5 marks

Explain about request and response message format with example. [5]

To communicate with a web server, the client makes calls over the network using HTTP (HyperText Transfer Protocol). A client makes an HTTP request for a resource, and the server sends back an HTTP response. --- An HTTP request message is sent from the client to the server. It consists of the foll...

Open this answer on its own page →

ASP.NET and ASP.NET MVC

2076 · 5 marks

Explain the components of ASP[5]

ASP.NET Core is designed to separate web logic, infrastructure, and core components from each other to provide a more development-friendly environment. The main components are organized into distinct layers. --- - This layer encapsulates the main business logic and UI logic of the application. - ...

Open this answer on its own page →