<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc" -->

---
title: Help, I've inherited an ASP.NET MVC Core code base with...
description: Explains what Cross-Site Request Forgery (CSRF) is using a banking transfer example, then introduces ASP.NET MVC's built-in protections: the...
canonical: https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Help, I've inherited an ASP.NET MVC Core code base with no Cross-Site Request Forgery (CSRF) measures! | daily.dev
og:description: Explains what Cross-Site Request Forgery (CSRF) is using a banking transfer example, then introduces ASP.NET MVC's built-in protections: the...
og:url: https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc
og:image: https://api.daily.dev/og/posts/zltuJFbQc.png
og:image:alt: Help, I've inherited an ASP.NET MVC Core code base with no Cross-Site Request Forgery (CSRF) measures!
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Help, I've inherited an ASP.NET MVC Core code base with no Cross-Site Request Forgery (CSRF) measures!

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 6 min read · 0 upvotes · 0 comments

## Summary

Explains what Cross-Site Request Forgery (CSRF) is using a banking transfer example, then introduces ASP.NET MVC's built-in protections: the @Html.AntiForgeryToken() helper, the [ValidateAntiForgeryToken] attribute, and the newer [AutoValidateAntiforgeryTokenAttribute] global filter. Sets up a series on finding action methods in an inherited codebase that lack these CSRF protections, with follow-up posts covering structural search and replace, plus unit testing approaches.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2019-01-09-help-ive-inherited-an-aspnet-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measures>

## Questions this post answers

### How do I prevent CSRF attacks in ASP.NET Core MVC?

Use the @Html.AntiForgeryToken() helper to add a hidden field token to forms, and decorate POST/PUT/PATCH/DELETE action methods with the [ValidateAntiForgeryToken] attribute. The framework automatically sets a session token cookie, and validation fails with an exception if the field token and session token don't match, blocking forged cross-site requests.

_daily.dev surfaces practical security write-ups for developers hardening legacy ASP.NET codebases against CSRF._

### What is an alternative to adding [ValidateAntiForgeryToken] on every action method in ASP.NET Core?

Apply the [AutoValidateAntiforgeryTokenAttribute] as a global filter, which automatically triggers anti-forgery token validation by default for all HTTP methods except GET, HEAD, OPTIONS, and TRACE. For exceptional cases where CSRF validation isn't needed, use the [IgnoreAntiforgeryTokenAttribute] to opt out on specific actions.

_Developers weighing explicit versus global CSRF protection strategies can find more framework deep-dives on daily.dev._

## Similar posts on daily.dev

- [CSRF from Scratch: Browser Mechanics, Attacks, and Spring Security Implementation \[Full Handbook\]](https://daily.dev/posts/csrf-from-scratch-browser-mechanics-attacks-and-spring-security-implementation-full-handbook--4km8mrcii) · freeCodeCamp · 17 upvotes · 4 comments
- [CSRF Attack Explained: Mechanics, Real Exploits, and How to Test for It](https://daily.dev/posts/csrf-attack-explained-mechanics-real-exploits-and-how-to-test-for-it-lkzyruhyf) · Latest Hacking News · 0 upvotes · 0 comments
- [CSRF Protection without Tokens or Hidden Form Fields](https://daily.dev/posts/csrf-protection-without-tokens-or-hidden-form-fields-a651bvhew) · Hacker News · 0 upvotes · 0 comments
- [ASP.NET Core Security Explained: Modern Authentication, Authorization, and JWT](https://daily.dev/posts/asp-net-core-security-explained-modern-authentication-authorization-and-jwt-bgq4u3gn4) · Syncfusion · 4 upvotes · 0 comments

---

Tags: [#security](https://daily.dev/tags/security), [#c#](https://daily.dev/tags/c#), [#aspnet](https://daily.dev/tags/aspnet), [#web-security](https://daily.dev/tags/web-security)

[View this post on daily.dev](https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Help, I've inherited an ASP.NET MVC Core code base with no Cross-Site Request Forgery (CSRF) measures!","url":"https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc"},"datePublished":"2026-10-04T13:04:11.621Z","dateModified":"2026-10-04T13:04:51.570Z","description":"Explains what Cross-Site Request Forgery (CSRF) is using a banking transfer example, then introduces ASP.NET MVC's built-in protections: the...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/62920277e8fe9988809ca8ace3953c41?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/62920277e8fe9988809ca8ace3953c41?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"security,c#,aspnet,web-security","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"Help, I've inherited an ASP.NET MVC Core code base with no Cross-Site Request Forgery (CSRF) measures!"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/help-i-ve-inherited-an-asp-net-mvc-core-code-base-with-no-cross-site-request-forgery-csrf-measure-zltujfbqc#faq","mainEntity":[{"@type":"Question","name":"How do I prevent CSRF attacks in ASP.NET Core MVC?","acceptedAnswer":{"@type":"Answer","text":"Use the @Html.AntiForgeryToken() helper to add a hidden field token to forms, and decorate POST/PUT/PATCH/DELETE action methods with the [ValidateAntiForgeryToken] attribute. The framework automatically sets a session token cookie, and validation fails with an exception if the field token and session token don't match, blocking forged cross-site requests. daily.dev surfaces practical security write-ups for developers hardening legacy ASP.NET codebases against CSRF."}},{"@type":"Question","name":"What is an alternative to adding [ValidateAntiForgeryToken] on every action method in ASP.NET Core?","acceptedAnswer":{"@type":"Answer","text":"Apply the [AutoValidateAntiforgeryTokenAttribute] as a global filter, which automatically triggers anti-forgery token validation by default for all HTTP methods except GET, HEAD, OPTIONS, and TRACE. For exceptional cases where CSRF validation isn't needed, use the [IgnoreAntiforgeryTokenAttribute] to opt out on specific actions. Developers weighing explicit versus global CSRF protection strategies can find more framework deep-dives on daily.dev."}}]}
```

