Tuesday, November 18, 2008

ASP.NET MVC Beta Captcha example

I was working on an ASP.NET MVC application (in vb.net) and I needed to include a captcha thingy.

Nick Berardi already made a captcha for ASP.NET MVC, so I used his implementation. But it didn't work right out the box. After some tweaking it was still not working. So Nick has emailed me some information and from that I've created a working sample that I'll post here.

I got this error when using the dll: Reference required to assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' containing the base class 'System.Web.Mvc.ActionFilterAttribute'. Add one to your project.
This while I had the dll referenced, but probably it was refering to and older dll.
Anyway, it's fixed now.



These are the modifications I made (compared to the default asp.net mvc beta project template:

- I changed web.config and added this httphandler in the system.web section:


- I changed global.asax to add some routes to ignore:
routes.IgnoreRoute("{handler}.ashx")
routes.IgnoreRoute("{controller}/{handler}.ashx")
routes.IgnoreRoute("{controller}/{action}/{handler}.ashx")

- I've added a new project ManagedFusion with the .cs files that made/modified by Nick and this was referenced in the asp.net mvc project.

Click here to download the captcha demo (vb.net) project

Update: Instead of Html.CaptchaTextBox("caption") you can also use this code:
Html.TextBox("captcha", "", New With {.autocomplete = "off", .maxlength = "5"})

Sunday, November 16, 2008

A simple crossbrowser semantic javascript menu

I needed a simple crossbrowser javascript menu. One that would work on IE6, IE7, Firefox and Safari. Well I didn't search for it on the internet because I wanted to have it as clean as possible so I've created my own.



Four hours later it was done and I was happy with the result. A crossbrowser javascript menu, which is easy skinnable and build for the semantic web, with less than 50 lines of javascript code. The html contains only 1 id (for building up the menu), but furthermore it doesn't contain any other id's, or style attributes. So a menu which only exists of UL's and LI's.



Another target for my menu was that it should work in html (4.01) and xhtml (1.0 and 1.1). If I would have searched for such a menu I'm sure it would take me longer than 4 hours to search/test/review the available javascript/dhtml menu's on the web.

You'll find an example here

It's tested on IE6, IE7, Firefox 3, Safari 3 (for Windows) and Google Chrome.