How to use it with WebApi?

Apr 15, 2013 at 9:30 PM
Edited Apr 15, 2013 at 10:43 PM
Hi, I'm trying to use it with MVC4 web api but CaptchaVerify is always true. There is something special to do for use it with WebAPI.

Moreover, isn't possible to use this.IsCaptchaValid because the htmlhelper doesn't work in an ApiController.
Coordinator
Apr 16, 2013 at 3:26 PM
Hi there,
I have no idea how to use the captcha with WebAPI.
Can you provide any example?

Regards,
Vyacheslav Volkov
Apr 19, 2013 at 12:54 AM
WebApi is a new kind of controller. When you create a controller using WebApi it inherits from ApiController and not from Controller.

ApiController belongs to System.Web.Http.ApiController and Controller belongs to System.Web.Mvc.Controller. So, your filters and helpers receive a BaseController object but if you are using webapi they fail ....
Coordinator
Apr 19, 2013 at 3:19 PM
I know what is WebAPI, but I don't comprehend how you can use the captcha with WebAPI.
WebAPI is built for all the other, non-human interactions your site or service needs to support.

Regards,
Vyacheslav Volkov
Apr 19, 2013 at 4:32 PM
WebAPI is not only for non human interaction. Is for transfer data. I have a SPA web client and my MVC normal controllers are in charge returning HTML. All my data transfer between the server and the client are through WebAPI by using JavaScript data sources. In my application I only download HTML, CSS and JavaScripts once and then all the communication between the client and the server is by WebAPI (Json data).

Look the section:
Calling the Web API with Javascript and jQuery in the next link

http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
Coordinator
Apr 19, 2013 at 5:15 PM
I understood what you want. Unfortunately captcha does not support these types of controllers. I can suggest to check the captcha use a normal MVC controller(see demo HomeController/AjaxForm2). I'll think about the possibility to add support for this feature in a future release.

Regards,
Vyacheslav Volkov