This project demonstrates authentication checks using controller attributes + IAsyncActionFilter, not runtime auth middleware.
- Active runtime auth path: Filters on controllers
- Inactive (legacy only):
CookieMiddleware,SessionMiddleware,JwtTokenMiddleware - Why: only controller endpoints are checked, static files are not scanned by custom auth logic.
CookieAuthFilter-> checksRequest.Cookies["email"]SessionAuthFilter-> checksHttpContext.Session.GetString("email")JwtCookieAuthFilter-> checksjwt_tokencookie, validates claims, and refreshes token cookie
Applied by controller attributes:
[CookieAuth]onCookieTestController[SessionAuth]onSessionTestController[JwtAuth]onJwtTestController
[AllowAnonymous] is still respected for setup/login endpoints.
Protected endpoints return JSON (success case):
{
"success": true,
"filter": "cookie|session|jwt",
"message": "...",
"timestampUtc": "2026-03-15T...Z"
}Filter failure for demo checks returns 401 JSON (no redirect):
{
"success": false,
"filter": "cookie|session|jwt",
"message": "Beginner-friendly reason",
"statusCode": 401,
"timestampUtc": "2026-03-15T...Z"
}GET /CookieTest/SetupCookie([AllowAnonymous])GET /CookieTest/Protected([CookieAuth])
GET /SessionTest/SetupSession([AllowAnonymous])GET /SessionTest/Protected([SessionAuth])
GET /JwtTest/SetupJwt([AllowAnonymous])GET /JwtTest/Protected([JwtAuth])
The Home page includes three interactive buttons:
- Try Cookie Filter
- Try Session Filter
- Try JWT Filter
Behavior:
- Click a button -> page calls
fetch()withAccept: application/json. - Response is parsed for both success (
200) and failure (401). - Status card updates with:
- Green success or red failure color
- SVG success/fail icon
- Message from JSON
- Last checked time/filter/status
- Retry button reruns the most recent check.
- Buttons are temporarily disabled while request is running.
No full-page navigation is used for these checks.
- Run app:
dotnet run --project AuthMiddlware/AuthMiddlware.csproj
- Open sign-in page:
/SignIn/Index
- Use one-click demo sign-in (prefilled credentials).
- On Home, click Try Filter buttons and observe JSON-driven status card.
Run integration tests:
dotnet test AuthMiddlware.Tests/AuthMiddlware.Tests.csproj --no-restoreWhat is validated:
- Protected checks return
401JSON before setup - Setup then protected returns
200JSON - JWT protected check refreshes
jwt_tokencookie - Static file
/css/site.cssis served normally
- Target framework is currently
net7.0(out-of-support warning appears during build/test). - Middleware files are kept intentionally for legacy/reference and rollback history.