Skip to content

Simple Getting Started Guide

valmont edited this page Aug 1, 2012 · 2 revisions

Install package from nuget: Install-Package SimpleHoneypot.MVC

###What is added to your solution###

  • SimpleHoneypot.dll
  • WebActivator.dll
  • App_Start directory
  • App_Start/SimpleHoneypot.cs

###Default configuration of SimpleHoneypot.cs###

public static void Start() {
			RegisterHoneypotInputNames(Honeypot.InputNames);
		}
		
		public static void RegisterHoneypotInputNames(HoneypotInputNameCollection collection) {
			//Honeypot will use 2 words at random to create the input name {0}-{1}
			collection.Add(new[]
						   {
							   "User",
							   "Name",
							   "Age",
							   "Question",
							   "List",
							   "Why",
							   "Type",
							   "Phone",
							   "Fax",
							   "Custom",
							   "Relationship",
							   "Friend",
							   "Pet",
							   "Reason"
						   });
		}

###Other configuration options###

By Default, Simple Honeypot will render an input with a CSS class name called 'input-imp-long'. You can change this CSS by calling Honeypot.SetCssClassName("newCssName") in the Start function of the SimpleHoneypot.cs class.

###The controller###

You will need to annotate the Action of your controller with the [Honeypot] Filter Attribute.

[Honeypot, HttpPost]
public ActionResult Comment(BlogComment comment) {
	/* Some Processing */
	return RedirectToAction("Index");
}

The HoneypotAttribute optionally takes a url to redirect to as a String [Honeypot("/Home/Honeytrap")]

###The View###

Next, you will need to add a call to the HoneypotInput HtmlHelper in your form.

@using SimpleHoneypot.HtmlHelpers
@model BlogComment

@using(Html.BeginForm("Comment", "Blog")) {
	@Html.EditorForModel()
	@Html.HoneypotInput()
	<p>
		<input type="submit" value="Comment" />
	</p>
}

###Adding a class to your style sheet###

By default Simple Honeypot will use 'input-imp-long' for the input generated. However, if you used the Honeypot.SetCssClassName("newCssName") you will need to use the custom css name.

.input-imp-long { display: none; }

or

.newCssName { display: none; }