Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Security
Google Cloud Platform icon
Labs

Sanitize User Input for C# Applications

In this lab, you will practice securing web applications against SQL Injection, XSS, and CSRF attacks. When you finish, you will have a fully functional ASP.NET Core MVC application with implemented protections for each vulnerability.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
Jul 30, 2025
Duration
1h 15m

Contact sales

By clicking submit, you agree to our Privacy Policy and Terms of Use.
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

    Sanitize User Input for C#: Concept Review

    You'll review core web vulnerabilities: SQL Injection, XSS, and CSRF. Learn how untrusted input, unencoded output, and missing request validation expose risks—and how to mitigate them in ASP.NET Core MVC apps.

  3. Challenge

    SQL Injection Vulnerability and Mitigation

    You'll analyze a C# console app with a SQL injection vulnerability caused by string concatenation. You'll then refactor it using parameterized queries with SqlCommand and test it with both valid and malicious inputs to confirm the fix.

  4. Challenge

    Cross-Site Scripting (XSS) Vulnerability and Prevention

    You'll build a Razor view in ASP.NET Core MVC that initially renders unencoded input, exposing an XSS risk. You'll then apply WebUtility.HtmlEncode and test with script payloads to confirm the secure version renders the input as harmless text.

  5. Challenge

    Cross-Site Request Forgery (CSRF) Prevention

    You'll create an ASP.NET Core MVC app with a state-changing form that lacks CSRF protection. You'll then add anti-forgery tokens and apply the ValidateAntiForgeryToken attribute to secure it and ensure POST requests come from trusted sources.

  6. Challenge

    Knowledge Check for Sanitize User Input 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.

About the author

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.

Real skill practice before real-world application

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.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight