Trapping spambots with honeypots in MVC
Posted 20 Nov 2011
Form spam is still a real issue for any public website. Spambots are mostly very primitive scripts. They’ll scan HTML for form fields, fill all of them with some value and submit the form. Using regular textbox fields, hidden from ‘real’ users by CSS, you can trick spam bots into filling in fields a normal user would leave blank. This gives you an easy way to tell people from bots.
Unobtrusive MVC honeypots
It’s quite straight forward to implement honeypot fields in ASP.NET MVC, but of course it should be as unobtrusive as possible. So, what I’ve come up with is an action filter to help out:
Html helper
To use the honeypot action filter, insert a form field and make it invisible using CSS.
This injects a label and text field:
If using this solution in a larger app you'll probably want to include the div in the helper and setup the CSS in the main style sheet.