c# - C# ASP.NET 中的 reCAPTCHA v3
问题描述
我正在尝试让 Google reCAPTCHA v3 在 ASP.NET WebForm 上运行。我使用的库是 BitArmory.ReCaptcha ( https://github.com/BitArmory/ReCaptcha ) 但示例代码无法编译:
//1. Get the client IP address in your chosen web framework
string clientIp = this.HttpContext.Connection.RemoteIpAddress.ToString();
string token = null;
string secret = "your_secret_key";
//2. Extract the `#captcha` field from the hidden HTML form in your chosen
web framework
if( this.Request.Form.TryGetValue("captcha", out var formField) )
{
token = formField;
}
//3. Validate the reCAPTCHA with Google
var captchaApi = new ReCaptchaService();
var result = await captchaApi.Verify3Async(token, clientIp, secret);
if( !result.IsSuccess || result.Action != "SOME_ACTION" || result.Score < 0.5 )
{
// The POST is not valid
return new BadRequestResult();
}
else{
//continue processing, everything is okay!
}
我在 this.HttpContext.Connection.RemoteIpAddress、this.Request.Form.TryGetValue 和 result.IsSuccess 上遇到错误(在 result.* 上等等)。该站点正在运行 .NET 4.8。这适用于 .NET Framework,还是仅适用于 .NET Core?
谢谢。
解决方案
推荐阅读
- javascript - 如何在 React 经典 `class` 组件中使用 React 钩子?
- javascript - 为重复代码制作一个函数
- python - 如何使用 pyspark 解析字段中包含换行符的 CSV 数据
- php - MySQL在一个语句中查询两个表
- typescript - TypeScript 可选类型与类型的区别 | 不明确的
- octave - octave 3 vs 4 脚本兼容性;Executable-Octave-Programs 的真实文档在哪里
- javascript - 检查是否选择了 jQuery 选项(在当前页面中)
- swift - Swift - ZPL,打开打印机时第一次打印时正确打印,但之后每次打印都不正确?
- blender - 插入 Blender 动画文件名帧数偏移
- elasticsearch - 如何将没有 id 的批量插入发送到 elasticsearch