recaptcha-net
recaptcha-net copied to clipboard
NullReference Exception
Hi i create ActonFilterAttribute and i have problem with null reference exception in recaptchaHelper.VerifyRecaptchaResponse().
This problem is only for version 2.
public class IsValidCaptcha : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var controller = (filterContext.Controller as Controller); if (controller == null) return;
var ms = filterContext.Controller.ViewData.ModelState;
var recaptchaHelper = controller.GetRecaptchaVerificationHelper();
if (String.IsNullOrEmpty(recaptchaHelper.Response))
{
ms.AddModelError("", "Captcha answer cannot be empty.");
}
var recaptchaResult = recaptchaHelper.VerifyRecaptchaResponse();
if (recaptchaResult != RecaptchaVerificationResult.Success)
{
ms.AddModelError("", "Incorrect captcha answer.");
}
}
}
at Recaptcha.Web.RecaptchaVerificationHelper.VerifyRecpatcha2Response(String privateKey) at SteamMarket.Logic.Common.Filters.IsValidCaptcha.OnActionExecuting(ActionExecutingContext filterContext) in G:___ORIK\SteamMarket\SteamMarket\SteamMarket.Logic\Common\Filters\IsValidCaptcha.cs:line 23 at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.InvokeActionMethodFilterAsynchronouslyRecursive(Int32 filterIndex)
I get this as well, on a few number of requests every day (I guess 5% at the most).
We're just using regular ASP.NET.
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Recaptcha.Web.RecaptchaVerificationHelper.VerifyRecpatcha2Response(String privateKey) at Recaptcha.Web.RecaptchaVerificationHelper.VerifyRecaptchaResponse() at Recaptcha.Web.UI.Controls.Recaptcha.Verify() at Web.Controls.RecaptchaHelper.Validate(Recaptcha recaptcha, String& errorMsg) in RecaptchaHelper.cs:line 20 at Web.User.btnSubmit_Click(Object sender, EventArgs e) in User.aspx.cs:line 58
what is the solution ?
@tanveery I can try to fix it but I'm out of ideas. Any help?