"A potentially dangerous Request.Form value was detected from the client" fix for ASP.NET MVC

Here is a gotcha that I found while I had my "WebForms" hat on.

Written by Jonathan "JD" Danylko • Last Updated: • MVC •

I've been working on a project and got the dreaded error:

"A potentially dangerous Request.Form value was detected from the client"

Well, after trying the "<@page validateRequest="false"...>", I realized that didn't work. So I started looking through the code and found the attribute:

[ValidateRequest(false)]

You need to attach the ValidateRequest(false) attribute to the method that is receiving the post.

Problem solved.

NOTE: However, make sure you are catching any type of malicious injections that could occur.

ASP.NET 8 Best Practices on Amazon

ASP.NET 8 Best Practices by Jonathan Danylko


Reviewed as a "comprehensive guide" and a "roadmap to excellence" with over 120 Best Practices for ASP.NET Core 8, Jonathan's first book by Packt Publishing explores proven techniques for every phase of the SDLC.

Learn industry-standard concepts to improve your coding, debugging, and deployment of ASP.NET Core websites.

Order now on Amazon.com button

Picture of Jonathan "JD" Danylko

Jonathan "JD" Danylko is an author, web architect, and entrepreneur who's been programming for over 30 years. He's developed websites for small, medium, and Fortune 500 companies since 1996.

He currently works at Insight Enterprises as an Architect.

When asked what he likes to do in his spare time, he replies, "I like to write and I like to code. I also like to write about code."

comments powered by Disqus