BotVerify for ASP: Complete Guide to Integration and Setup
Overview
BotVerify is a bot-detection/check service (assumed API-based). This guide shows a practical, end-to-end integration into an ASP (classic ASP or ASP.NET?) web application. I will assume you mean ASP.NET (C#) MVC or Web Forms; if you need classic ASP, say so and I’ll provide that version.
Goals
- Add BotVerify client-side challenge to forms/pages
- Verify tokens server-side in ASP.NET
- Handle errors, retries, and logging
- Securely store and use API keys
Prerequisites
- ASP.NET project (MVC or Web Forms) using .NET Framework 4.7+ or .NET Core/6+
- HTTPS enabled for your site
- BotVerify site key (public) and secret key (private)
- NuGet access to add packages (if using HttpClient helpers)
1) Register and get keys
- Sign up for BotVerify and register your domain.
- Copy the Site Key (used in the browser) and Secret Key (used server-side). Store the secret in environment variables or app secrets (never in source code).
2) Client-side: include BotVerify widget
- Add the BotVerify script to pages that will present a challenge, typically in your form view or layout:
html
<script src=“https://cdn.botverify.example/widget.js” async defer></script>
- Render the widget on the form with your site key (example for Razor view):
html
<form method=“post” action=“/Account/Submit”> <div id=“botverify-container”></div> <input type=“hidden” id=“botverify-token” name=“botverifyToken” /> <button type=“submit”>Submit</button> </form> <script> BotVerify.render(’#botverify-container’, { siteKey: ‘YOUR_SITE_KEY’, callback: function(token) { document.getElementById(‘botverify-token’).value = token; } }); </script>
- Behavior: the widget produces a short-lived token on success; the token is posted with the form.
3) Server-side: verify token in ASP.NET (C#)
- Use HttpClient to call BotVerify’s verification endpoint (example URL: https://api.botverify.example/verify).
- Verify on every action that accepts user input (login, register, contact forms).
Example helper class:
csharp
using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; public class BotVerifyService { private readonly HttpClient _http; private readonly string _secretKey; public BotVerifyService(HttpClient http, string secretKey) { _http = http; _secretKey = secretKey; } public async Task<BotVerifyResult> VerifyAsync(string token, string remoteIp = null) { var req = new { secret = _secretKey, response = token, remoteip = remoteIp }; var resp = await http.PostAsJsonAsync(“https://api.botverify.example/verify”, req); resp.EnsureSuccessStatusCode(); var json = await resp.Content.ReadAsStringAsync(); return JsonSerializer.Deserialize<BotVerifyResult>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); } } public class BotVerifyResult { public bool Success { get; set; } public double Score { get; set; } // if BotVerify returns a score public string Action { get; set; } // optional public string[] ErrorCodes { get; set; } }
- In your controller action:
csharp
[HttpPost] public async Task<IActionResult> Submit(MyFormModel model) { var token = Request.Form[“botverifyToken”].ToString(); var ip = HttpContext.Connection.RemoteIpAddress?.ToString(); var result = await _botVerifyService.VerifyAsync(token, ip); if (!result.Success || result.Score < 0.5) { ModelState.AddModelError(””, “Bot verification failed.”); return View(model); } // proceed with normal processing }
Adjust score threshold (if applicable) to your risk tolerance.
4) Error handling and retries
- Treat network errors as transient: retry 1–2 times with short backoff.
- Log failures and error codes for analysis.
- If verification fails due to missing/expired token, prompt user to reload the widget.
5) Security best practices
- Keep secret key out of source: use environment variables, Azure Key Vault, AWS Secrets Manager, or user-secrets in development.
- Verify tokens on every critical action server-side — never rely on client-only checks.
- Validate token freshness and intended action (if BotVerify supports action binding).
- Rate-limit verification endpoint calls per IP to avoid abuse.
6) UX considerations
- Use invisible or low-friction verification where available to reduce friction.
- On mobile, ensure the widget scales and consider fallback mechanisms.
- Provide clear error messages like “Please confirm you are not a bot” rather than technical errors.
7) Logging and monitoring
- Log success/failure counts, error codes, and scores.
- Monitor trends (sudden spike in failures may indicate attack).
- Alert on sustained elevation in bot traffic.
8) Testing
- Use BotVerify’s test keys or sandbox mode for development.
- Simulate failed and successful responses to ensure flows handle both.
- Test with real browsers and common form flows.
9) Advanced: adaptive responses
- Use score-based logic (e.g., 0.0–1.0): allow low-risk submissions, present step-up challenge for medium risk, block or require MFA for high risk.
- Combine BotVerify with rate-limiting, device fingerprinting, and behavioral analytics for layered defense.
Quick checklist
- Obtain site & secret keys
- Add widget script and hidden token field
- Implement server-side verification with HttpClient
- Store secret securely
- Add logging, retry, and alerting
- Test in sandbox and production
If you want, I can generate a ready-to-use NuGet-friendly BotVerifyService class for your specific ASP.NET version or produce a classic ASP example.
Leave a Reply