I’m implementing the recaptcha control from google.
I built a simple c# test project from their example and all works. Now, instead of having the PublicKey and PrivateKey in the aspx page, I’d rather assign these values at run time as they will most likely be pulled from either the web.config or a database table.
I tried the following in the Page_Load
protected void Page_Load(object sender, EventArgs e) {
recaptcha.PublicKey = "<deleted for obvious reasons>";
recaptcha.PrivateKey = "<ditto>";
}
but I get an error stating “reCAPTCHA needs to be configured with a public & private key.”
I also tried overriding the oninit method of the page and assigning the values there, but no joy.
Any ideas on where this needs to go?
Try using the value of
setincodebehindin your tag, like this:That should let you set the keys in the codebehind properly. There are a couple of other ways to do it as well. For example, you can get the values from a static class like this:
Where
RecaptchaSettingsis a class you provide. Or, you could put the keys into anappSettingssection of your web.config, and access them like this:Hope that helps.