<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq" -->

---
title: ASP.NET MVC preview 5's AntiForgeryToken helper method...
description: ASP.NET MVC preview 5 introduces the HtmlHelper.AntiForgeryToken method, which renders a hidden input field with a unique token on a view. Pairing this with...
canonical: https://daily.dev/posts/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: ASP.NET MVC preview 5's AntiForgeryToken helper method and attribute | daily.dev
og:description: ASP.NET MVC preview 5 introduces the HtmlHelper.AntiForgeryToken method, which renders a hidden input field with a unique token on a view. Pairing this with...
og:url: https://daily.dev/posts/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq
og:image: https://api.daily.dev/og/posts/itJmgo4FQ.png
og:image:alt: ASP.NET MVC preview 5's AntiForgeryToken helper method and attribute
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.

# ASP.NET MVC preview 5's AntiForgeryToken helper method and attribute

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

## Summary

ASP.NET MVC preview 5 introduces the HtmlHelper.AntiForgeryToken method, which renders a hidden input field with a unique token on a view. Pairing this with the [ValidateAntiForgeryToken] action filter attribute validates each form submission against that token, and tampering with the field or submitting from a different view instance throws an AntiForgeryTokenValidationException.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2008-09-01-aspnet-mvc-preview-5s-antiforgerytoken-helper-method-and-attribute>

## Questions this post answers

### How do I use the AntiForgeryToken helper in ASP.NET MVC preview 5 to prevent CSRF attacks?

Place <%=Html.AntiForgeryToken()%> in a view to render a hidden input field named __MVC_AntiForgeryToken containing a unique generated value. Decorate the corresponding action method with the [ValidateAntiForgeryToken] attribute so every form post is checked against that token; tampering with the field or posting from a different rendered view instance throws an AntiForgeryTokenValidationException.

_daily.dev surfaces practical ASP.NET MVC security patterns like this for developers hardening form submissions against CSRF._

## Similar posts on daily.dev

- [The silent filter: How an ASP.NET MVC quirk became a security leak](https://daily.dev/posts/the-silent-filter-how-an-asp-net-mvc-quirk-became-a-security-leak-wec0w8625) · The Art of Simplicity · 2 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
- [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
- [Django CSRF Token: Misconfiguration or Misunderstanding?](https://daily.dev/posts/django-csrf-token-misconfiguration-or-misunderstanding--fr0seue9w) · InfoSec Write-ups · 0 upvotes · 0 comments

---

Tags: [#.net](https://daily.dev/tags/.net)

[View this post on daily.dev](https://daily.dev/posts/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq)

```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":"ASP.NET MVC preview 5's AntiForgeryToken helper method and attribute","url":"https://daily.dev/posts/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq"},"datePublished":"2026-10-04T13:05:04.512Z","dateModified":"2026-10-04T13:11:24.444Z","description":"ASP.NET MVC preview 5 introduces the HtmlHelper.AntiForgeryToken method, which renders a hidden input field with a unique token on a view. Pairing this with...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a1b45969444a29395b6a324e970c8e10?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a1b45969444a29395b6a324e970c8e10?_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/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":".net","timeRequired":"PT1M"}
{"@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":"ASP.NET MVC preview 5's AntiForgeryToken helper method and attribute"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/asp-net-mvc-preview-5-s-antiforgerytoken-helper-method-and-attribute-itjmgo4fq#faq","mainEntity":[{"@type":"Question","name":"How do I use the AntiForgeryToken helper in ASP.NET MVC preview 5 to prevent CSRF attacks?","acceptedAnswer":{"@type":"Answer","text":"Place <%=Html.AntiForgeryToken()%> in a view to render a hidden input field named __MVC_AntiForgeryToken containing a unique generated value. Decorate the corresponding action method with the [ValidateAntiForgeryToken] attribute so every form post is checked against that token; tampering with the field or posting from a different rendered view instance throws an AntiForgeryTokenValidationException. daily.dev surfaces practical ASP.NET MVC security patterns like this for developers hardening form submissions against CSRF."}}]}
```

