Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #17

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Akismet.Net

Complete and full-featured Akismet client for .NET

Existing libraries don't allow for all of the possible options available in the Akismet API and the source code is not public. This library is meant to fix that.
Expand All @@ -9,7 +10,9 @@ It is also multi-targeted to support as many applications as possible.

Meant to be a drop-in replacement for the leading Akismet library with minimal changes so the class names are the same. However some properties have been removed because of redundancy.

Example usage:
## Example usage:

### .NET Framework

```csharp
var model = new ContactModel();
Expand All @@ -31,8 +34,8 @@ AkismetComment comment = new AkismetComment
IsTest = "false",
BlogCharset = "UTF-8",
BlogLanguage = "en-US",
CommentDate = DateTime.UtcNow.ToString("s"), // ISO-8601 format
CommentPostModified = DateTime.UtcNow.ToString("s"), // ISO-8601 format
CommentDate = DateTime.UtcNow.ToString("O"), // ISO-8601 format
CommentPostModified = DateTime.UtcNow.ToString("O"), // ISO-8601 format
UserRole = "administrator",
RecheckReason = "edit",
HoneypotFieldName = "honeypot",
Expand All @@ -51,6 +54,22 @@ foreach (string err in akismetResult.Errors)
// - DebugHelp (X-akismet-debug-help header value, if present)
```

### .NET Core/.NET 5+ Usage Modifications

```csharp
string ip = Request.Headers["CF-Connecting-IP"].ToString() ?? _contextAccessor.HttpContext?.Connection.RemoteIpAddress?.ToString() ?? "";
if (String.IsNullOrWhiteSpace(ip))
ip = _contextAccessor.HttpContext?.GetServerVariable("REMOTE_HOST") ?? "";
AkismetComment comment = new AkismetComment
{
// ... other properties set as above
UserAgent = Request.Headers[HeaderNames.UserAgent],
Referrer = Request.Headers[HeaderNames.Referer]
};
```

### Notes

If `HoneypotFieldName` and `HoneypotFieldValue` are supplied then the library will add these two values to the request:

`honeypot_field_name=honeypot&honeypot=blah`