Featured resource
Forrester Wave Report 2025
Pluralsight named a Leader in the Forrester Wave™

Our tech skill development platform earned the highest scores possible across 11 criteria.

Learn more
  • Labs icon Lab
  • Security
Google Cloud Platform icon
Labs

Secure Session Management for C# Applications

In this lab, you’ll practice modern session management and authentication techniques in ASP.NET Core. You’ll begin with a brief concept of secure session cookies and JSON Web Tokens (JWT). Then, you’ll create a weak cookie-based session, enhance it (Secure flag, HttpOnly, SameSite, short idle timeout), and finally transition to JWTs—learning to issue, validate, and rotate access tokens statelessly.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 1h 15m
Published
Clock icon Jun 05, 2025

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Getting Started in the Lab Environment

    Here are the initial instructions and explanation of the lab environment. Read this while your environment is busy creating itself from nothing. Yes, this violates physics; we know. How fun!

  2. Challenge

    The Foundations of Secure Session Management and Token-Based Authentication

    Before diving into coding, review the threats that session cookies and tokens need to defend against, including session fixation, XSS-assisted cookie theft, cross-site request forgery (CSRF), and replay attacks. Additionally, you'll compare server-stored sessions with stateless JWTs to ensure the hands-on tasks align with the architectural context.

  3. Challenge

    Baseline: Insecure Cookie Session

    You'll create a basic ASP.NET Core MVC or minimal API project that uses the default in-memory session middleware. By default, the session cookie is sent without Secure or SameSite flags and has a timeout of 20 minutes. You'll verify these settings using curl or your browser’s DevTools.

  4. Challenge

    Hardening the Session Cookie

    You'll enhance the baseline by configuring secure options in AddSession and UseSession. You'll require HTTPS, set the cookie as HttpOnly, configure SameSite=Strict, and reduce the idle timeout to two minutes. You'll then re-run the test and confirm the updated flags in the browser.

  5. Challenge

    Stateless Authentication with JWT

    You'll switch from cookie-based sessions to JWT bearer authentication. You'll set up a login endpoint that generates a signed token using HS256, implement AddAuthentication("Bearer"), and secure the /api/secure route with [Authorize]. You'll demonstrate successful access when the token is valid and provide automatic 401 responses when the token is missing, expired, or altered.

  6. Challenge

    Knowledge check for Secure Session Management for C# Applications

    In this challenge, you will answer some assessment questions that will test your understanding of the concepts you learned throughout this lab.

Sean Wilkins is an accomplished networking consultant and writer for infoDispersion (www.infodispersion.com) who has been in the IT field for over 20 years working with several large enterprises.

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.