O kadar kolay:
- Senin git google ReCaptcha yönetici paneline
- Aşağıdaki resim gibi yeni bir sitenin alan adlarını
localhost& 127.0.0.1alanlarına ekleyin .

Güncelleme:
Sorunuzun nasıl ayarlanacağını ise reCaptchalocalhost içinde kullanmak için Google sitesinde, sonra ben olmuştur yukarıda yazdım ama kullandığınız nasıl olduğunu merak eden varsa reCAPTCHAüzerine hem localhost ve website hosttarafından kontrolörünüze minimal kodları ve benzeri bazı kodları önlemek ConfigurationManager.AppSettings["ReCaptcha:SiteKey"]sonra içinde Cevabımdaki bu ekstra açıklama ve kodlarda size yardımcı oluyorum.
Aşağıdaki GET ve POST işlemlerini beğendiniz mi?
ReCaptcha'yı destekler ve reCaptcha'yı işlemek için başka kodlara ihtiyaç duymaz.
[HttpGet]
[Recaptcha]
public ActionResult Register()
{
// Your codes in GET action
}
[HttpPost]
[Recaptcha]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterViewModel model, string reCaptcha_SecretKey){
// Your codes in POST action
if (!ModelState.IsValid || !ReCaptcha.Validate(reCaptcha_SecretKey))
{
// Your codes
}
// Your codes
}
In Görünüm: ( referans )
@ReCaptcha.GetHtml(@ViewBag.publicKey)
@if (ViewBag.RecaptchaLastErrors != null)
{
<div>Oops! Invalid reCAPTCHA =(</div>
}
Kullanmak için
A)ActionFilter Web projenize aşağıdakileri ekleyin :
public class RecaptchaAttribute : FilterAttribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
var setting_Key = filterContext.HttpContext.Request.IsLocal ? "ReCaptcha_Local" : "ReCaptcha";
filterContext.ActionParameters["ReCaptcha_SecretKey"] = ConfigurationManager.AppSettings[$"{setting_Key}:SecretKey"];
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
var setting_Key = filterContext.HttpContext.Request.IsLocal ? "ReCaptcha_Local" : "ReCaptcha";
filterContext.Controller.ViewBag.Recaptcha = ReCaptcha.GetHtml(publicKey: ConfigurationManager.AppSettings[$"{setting_Key}:SiteKey"]);
filterContext.Controller.ViewBag.publicKey = ConfigurationManager.AppSettings[$"{setting_Key}:SiteKey"];
}
}
B) Ekle reCaptchaikisi için ayarları anahtarları localhost& websitesenin buna benzer webconfigdosyası:
<appSettings>
<!-- RECAPTCHA SETTING KEYS FOR LOCALHOST -->
<add key="ReCaptcha_Local:SiteKey" value="[Localhost SiteKey]" />
<add key="ReCaptcha_Local:SecretKey" value="[Localhost SecretKey]" />
<!-- RECAPTCHA SETTING KEYS FOR WEBSITE -->
<!--<add key="ReCaptcha:SiteKey" value="[Webite SiteKey]" />
<add key="ReCaptcha:SecretKey" value="[Webite SecretKey]" />-->
<!-- OTHER SETTING KEYS OF YOUR PROJECT -->
</appSettings>
Not: Bu şekilde , eylemler ve Görünümlerinizde post eylemde veya reCaptcha için manuel olarak herhangi bir reCaptcha_SecretKeyparametre ayarlamanıza gerek kalmadı , hepsi projeyi localhost veya web sitesinde çalıştırdığınıza bağlı olarak uygun zamanda uygun değerlerle otomatik olarak doldurulacaktır. .😉ViewBag