Coder Social home page Coder Social logo

Comments (8)

radl97 avatar radl97 commented on May 19, 2024

It seems that from 2.2.5 to 3.0.0 the syntax changed:

@(Html.Recaptcha(recaptchaSettings.Value))

should be

@(Html.Recaptcha<RecaptchaV3HiddenInput>(recaptchaSettings.Value))

I think.

See this part of README for more info.

from recaptcha.aspnetcore.

enemaerke avatar enemaerke commented on May 19, 2024

Just hit the exact same issue :)

Could this be related to some culture/resource file thing or a new behavior around stringifying things? It seems, from quickly looking into the Templates file, that it fails in a null check here (https://github.com/TimothyMeadows/reCAPTCHA.AspNetCore/blob/master/reCAPTCHA.AspNetCore/Templates/RecaptchaV3HiddenInput.cs#L307) so maybe the new stuff requires you to always provide language and actions?

from recaptcha.aspnetcore.

shelland avatar shelland commented on May 19, 2024

@radl97 Yep, I know. I'm using it exactly in the same way as it described in documentation including version type parameters.

from recaptcha.aspnetcore.

enemaerke avatar enemaerke commented on May 19, 2024

Not sure if this helps, but my error was incorrectly reading from the appSettings/appConfig. Once I got that sorted, I no longer hit this issue

from recaptcha.aspnetcore.

TimothyMeadows avatar TimothyMeadows commented on May 19, 2024

Will look into this today as time permits. It's likely it might be related to Action not being supplied. The new version moved from using functional programming to more model based. In the event it's missing a value you can always specify a constructed model yourself here:

@(Html.Recaptcha<RecaptchaV3HiddenInput>(recaptchaSettings.Value, MyRecaptchaV3HiddenInputModel))

from recaptcha.aspnetcore.

TimothyMeadows avatar TimothyMeadows commented on May 19, 2024

Looks like this is from 2 reasons: The second reason seems to have been resolved but will add it here anyway just for someone reading this.

The first is there is no default for Actions in V3 when it should be defaulted to "homepage". This will be resolved in the next version. You can fix this now by specifying a constructed model yourself rather than depending on the class model defaults.

The second issue is the original code you posted here is not using T to specify your version. I know you resolved this but this is likely be the most common issue coming from 2 to 3 for users reading. You no long use "Version": "" in JSON to denote which version of recaptcha the library is using. Please check the docs and use the correct model in Html.Recaptcha<T>.

from recaptcha.aspnetcore.

TimothyMeadows avatar TimothyMeadows commented on May 19, 2024

This should now be resolved in 3.0.1. Please reopen this issue if it persists. Thanks to everyone for assistance provided.

from recaptcha.aspnetcore.

Chandinipt avatar Chandinipt commented on May 19, 2024

Hi Tim,
I am hitting this issue in my code.
Installed version: 3.0.10

Controller has it injected:

public ServiceController(RheaWebsiteDB db, IRecaptchaService recaptcha) //injecting the dbcontext { _db = db; this._recaptcha = recaptcha; }

The relevant action code:
[HttpPost] //TODO: Removed this because it doesn't work anymore , Recaptcha.RecaptchaControlMvc.CaptchaValidator] [ValidateRecaptcha] public async Task<ActionResult> RequestAQuote(Quote quote, bool captchaValid, string captchaErrorMessage) { var recaptcha = await _recaptcha.Validate(Request); if (!recaptcha.success) ModelState.AddModelError("captcha", captchaErrorMessage);

The code in the view:

`@using reCAPTCHA.AspNetCore
@using reCAPTCHA.AspNetCore.Versions
@using Microsoft.Extensions.Options

@Inject IOptions RecaptchaSettings

----other stuff

            <div>
                @(Html.Recaptcha<RecaptchaV3HiddenInput>(RecaptchaSettings?.Value))
                
                @Html.ValidationMessage("captcha")
            </div>

`

Have also tried supplying a new RecaptchaV3HiddenInput() object to the Html.recaptcha call. And changing it to version RecaptchaV2Checkbox. But still hitting the ArgumentNullException as shown below:

ArgumentNullException: Value cannot be null. (Parameter 'objectToConvert')
reCAPTCHA.AspNetCore.Templates.RecaptchaV3HiddenInputBase+ToStringInstanceHelper.ToStringWithCulture(object objectToConvert)
reCAPTCHA.AspNetCore.Templates.RecaptchaV3HiddenInput.TransformText()
reCAPTCHA.AspNetCore.RecaptchaHelper.Recaptcha(IHtmlHelper helper, RecaptchaSettings settings, T model)
AspNetCore.Areas_Services_Views_Service_RequestAQuote.ExecuteAsync() in RequestAQuote.cshtml
+
@(Html.Recaptcha(RecaptchaSettings.Value, new RecaptchaV3HiddenInput()))

Thank you

from recaptcha.aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.