This is pretty common error(?) you get when you try to POST any data with ASP.NET MVC via Ajax. Pretty easy to fix with [ValidateInput(false)]...Its annoying as hell because if you have a say a "home" page with many partials from many controllers, you need to add to EVERY controller...blargh!
A handy trick if you want to pass html-like characters in a field without disabling validation outright is to put two underscores in front of the fields name which will let that field through, ie: name=" __html"
One of many reasons I really don't like the ASP.NET stack more and more, its so general purpose and if anything aimed at the casual developers its sickening that in order to get it close to what you want you have to go and do more work (often runtime work) to turn OFF all the useless crap thats turned on by default..
This is why I don't think conventions are great in library code, just WHO are you targeting and why not just have sample code/templates to define conventions.
Conventions should exist in the 'implementation' (the app) not its frameworks, if you DO put a convention in your framework then you best seriously think about how you design it for pluggability.
for security purposes this is worthless as there are many known ways around this protection. you just have to encode the characters differently. if anyone wants to hack your site he still can do it with standard techniques. only people not wanting to hack the site are suffering.
a better solution would have been to make the <%= %> syntax html-encode by default which anyway is what you want most of the time.
this blog has removed my html: < % = % >. thats exactly as wrong as asp.net filtering. why not just encode html chars and allow them? this is guaranteed to be safe while filtering is not and provides a less good user experience.
just one more thing: this is not safe by default, because there are easy ways around it. html-encoding all user input by default would be safe by default. oh you just cannot let people make security descisions. they get it wrong all the time. it is like the windows lan manager storing hashed passwords in two halfes instead of one whole. anyone who does not understand the problem with that should not design an authentication system at all.
That annoys the hell out of me. Ironically our production app has an issue with this exception, even though we've turned it off at the web.config level and in our BaseController. It occurs about once a week and we can't locate the data that is causing it.
@Duckie: Our app is on the large size. We have about 60 controllers with over 600 actions. I'd rather have something in the controller infrastructure than decorating everything with that.
Comment preview
Comments have been closed on this topic.
Markdown formatting
ESC to close
Markdown turns plain text formatting into fancy HTML formatting.
Phrase Emphasis
*italic* **bold**
_italic_ __bold__
Links
Inline:
An [example](http://url.com/ "Title")
Reference-style labels (titles are optional):
An [example][id]. Then, anywhere
else in the doc, define the link:
[id]: http://example.com/ "Title"
> Email-style angle brackets
> are used for blockquotes.
> > And, they can be nested.
> #### Headers in blockquotes
>
> * You can quote a list.
> * Etc.
Horizontal Rules
Three or more dashes or asterisks:
---
* * *
- - - -
Manual Line Breaks
End a line with two or more spaces:
Roses are red,
Violets are blue.
Fenced Code Blocks
Code blocks delimited by 3 or more backticks or tildas:
```
This is a preformatted
code block
```
Header IDs
Set the id of headings with {#<id>} at end of heading line:
## My Heading {#myheading}
Tables
Fruit |Color
---------|----------
Apples |Red
Pears |Green
Bananas |Yellow
Definition Lists
Term 1
: Definition 1
Term 2
: Definition 2
Footnotes
Body text with a footnote [^1]
[^1]: Footnote text here
Abbreviations
MDD <- will have title
*[MDD]: MarkdownDeep
FUTURE POSTS
Partial writes, IO_Uring and safety - about one day from now
Configuration values & Escape hatches - 4 days from now
What happens when a sparse file allocation fails? - 6 days from now
NTFS has an emergency stash of disk space - 8 days from now
Challenge: Giving file system developer ulcer - 11 days from now
And 4 more posts are pending...
There are posts all the way to Feb 17, 2025
RECENT SERIES
Challenge
(77): 20 Jan 2025 - What does this code do?
Answer
(13): 22 Jan 2025 - What does this code do?
Comments
Lol. Fun times.
This is pretty common error(?) you get when you try to POST any data with ASP.NET MVC via Ajax. Pretty easy to fix with [ValidateInput(false)]...Its annoying as hell because if you have a say a "home" page with many partials from many controllers, you need to add to EVERY controller...blargh!
err, any POST data with HTML or HTML-like characters.
A handy trick if you want to pass html-like characters in a field without disabling validation outright is to put two underscores in front of the fields name which will let that field through, ie: name=" __html"
@Jeff, you can inherit from BaseController and set its "ValidateRequest = false" in its constructor (or wherever) only once.
I never liked the attributes :)
One of many reasons I really don't like the ASP.NET stack more and more, its so general purpose and if anything aimed at the casual developers its sickening that in order to get it close to what you want you have to go and do more work (often runtime work) to turn OFF all the useless crap thats turned on by default..
This is why I don't think conventions are great in library code, just WHO are you targeting and why not just have sample code/templates to define conventions.
Conventions should exist in the 'implementation' (the app) not its frameworks, if you DO put a convention in your framework then you best seriously think about how you design it for pluggability.
for security purposes this is worthless as there are many known ways around this protection. you just have to encode the characters differently. if anyone wants to hack your site he still can do it with standard techniques. only people not wanting to hack the site are suffering.
a better solution would have been to make the <%= %> syntax html-encode by default which anyway is what you want most of the time.
this blog has removed my html: < % = % >. thats exactly as wrong as asp.net filtering. why not just encode html chars and allow them? this is guaranteed to be safe while filtering is not and provides a less good user experience.
just one more thing: this is not safe by default, because there are easy ways around it. html-encoding all user input by default would be safe by default. oh you just cannot let people make security descisions. they get it wrong all the time. it is like the windows lan manager storing hashed passwords in two halfes instead of one whole. anyone who does not understand the problem with that should not design an authentication system at all.
That annoys the hell out of me. Ironically our production app has an issue with this exception, even though we've turned it off at the web.config level and in our BaseController. It occurs about once a week and we can't locate the data that is causing it.
@Dmtriy - doh, so obvious! Thanks!
Chris: Cant you just log the error and fix it :-)?
Anyways, you just need a [ValidateInput(false)] on the action, asp.net mvc doesnt seem to care about the setting in web.config.
@Duckie: Our app is on the large size. We have about 60 controllers with over 600 actions. I'd rather have something in the controller infrastructure than decorating everything with that.
Comment preview