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.
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]
2079 · 5 marks
Define HTTP. Explain the MVC pattern. [5]
Show solved answerHide 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:
- The user sends a request through the View (browser).
- The Controller receives and processes the HTTP request.
- The Controller interacts with the Model to retrieve or update data.
- The updated Model data is passed back to the View.
- The View renders and displays the result to the user.
Advantages of MVC Pattern
| Feature | Benefit |
|---|---|
| Separation of Concerns | Each component has a distinct responsibility |
| Testability | Components can be tested independently |
| Maintainability | Easy to modify one component without affecting others |
| Reusability | Models 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."
Request and Response Message Format
2078 · 5 marks
Explain about request and response message format with example. [5]
ASP.NET and ASP.NET MVC
Make Unit 3 stick
Practice CSC378 with flashcards & quizzes