You are required to build a Student Portal Web Application using ASP.NET Core middleware.
This project will test your understanding of the middleware pipeline and the extension methods:
UseRunMapMapWhenUseWhen
Your application should behave differently depending on the request path, query string, and conditions.
- Add a logging middleware using
Usethat:- Logs the HTTP method and request path to the console before the request is processed.
- Logs
"Response sent"after the request is processed.
- This middleware must call
next()so the pipeline continues.
-
Implement a
Runmiddleware at the root (/) that returns:Welcome to the Student Portal -
This middleware must terminate the pipeline.
-
Create a branch for
/students:-
Inside the branch, add a middleware (
Use) that logs"Inside Students branch". -
Add a terminal
Runthat returns:Student Management Section
-
-
Create another branch for
/teachers:-
Inside the branch, add a terminal
Runthat returns:Teacher Management Section
-
-
Add a
MapWhenmiddleware that:-
If the query string contains
?admin=true, branches to an admin section. -
The admin section should respond with:
Admin Dashboard
-
-
If the query string does not contain
admin=true, continue the normal pipeline.
- Use
UseWhento add middleware only for requests where the path starts with/api.- In this condition, log
"API Request detected". - Still allow the request to continue to the rest of the pipeline.
- In this condition, log
- Add a final
Runmiddleware that handles all requests not already handled.-
Respond with:
Page Not Found
-
- A working ASP.NET Core project (
Program.cs) implementing all the above requirements. - Students must not use MVC, minimal APIs, or controllers β only middleware.
| Requirement | Points |
|---|---|
Logging middleware with Use works |
15 |
Root / handled with Run |
10 |
/students branch works with Map |
15 |
/teachers branch works with Map |
10 |
MapWhen handles ?admin=true correctly |
15 |
UseWhen logs only /api requests |
15 |
Fallback middleware (Page Not Found) |
10 |
| Code cleanliness & comments | 10 |
| Total | 100 |
- Request
GET /β Response:Welcome to the Student Portal - Request
GET /studentsβ Logs"Inside Students branch", Response:Student Management Section - Request
GET /teachersβ Response:Teacher Management Section - Request
GET /anythingβ Response:Page Not Found - Request
GET /api/dataβ Logs"API Request detected", Response:Page Not Found(since no specific handler) - Request
GET /?admin=trueβ Response:Admin Dashboard