Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/usercode/aspnetcore.honeypot
Simple honeypot implementation for ASP.NET Core to detect bot posts
https://github.com/usercode/aspnetcore.honeypot
aspnet honeypot
Last synced: about 1 month ago
JSON representation
Simple honeypot implementation for ASP.NET Core to detect bot posts
- Host: GitHub
- URL: https://github.com/usercode/aspnetcore.honeypot
- Owner: usercode
- License: mit
- Created: 2018-07-28T14:47:22.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-04-03T18:50:45.000Z (9 months ago)
- Last Synced: 2024-11-13T02:42:02.310Z (about 2 months ago)
- Topics: aspnet, honeypot
- Language: C#
- Homepage:
- Size: 35.2 KB
- Stars: 16
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AspNetCore.Honeypot
It's a simple honeypot implementation for ASP.NET Core to detect bot posts.
[![nuget](https://img.shields.io/nuget/v/AspNetCore.Honeypot.svg)](https://www.nuget.org/packages/AspNetCore.Honeypot)
## How to use it ##1. Register honeypot service.
```cs
public void ConfigureServices(IServiceCollection services)
{
services.AddHoneypot();
}
```2. Add tag helper to _ViewImports.cshtml
```cs
@addTagHelper *, AspNetCore.Honeypot
```3. Place any honeypot tag to a form with a custom name (e.g. "name", "email" or "city") and use *your* css class to hide it.
```html
```
4. Place one time-based honeypot tag.
```html```
6. Bot detection handling
4.1 Place the honeypot attribute to your action method for automatic bot detection handling.
```cs
[Honeypot]
[HttpPost]
public async Task PostRegister(RegisterViewModel registerData)
{
//..
}
```4.2 Use the extension method to handle bot detection by yourself.
```cs
[HttpPost]
public async Task PostRegister(RegisterViewModel registerData)
{
if (HttpContext.IsHoneypotTrapped())
{
ModelState.Clear();
ModelState.AddModelError("", "bot detection");//log
return View("Register", new RegisterViewModel());
}
}
```