API Reference
BotManager .NET Agent provides methods to detect page requests and API requests.
Applying Page Request Detection
Call BotManager.DetectPage() to detect macro activities in HTTP requests.
Code Example:
using BotManagerDotNetAgent.Domain;
using System.Collections.Generic;
namespace MyApplication
{
public class ExamplePageHandler {
public void HandleRequest(object request, object response) {
// When passing customId
var params = new Dictionary<string, string> {
{"customId", "exampleCustomId"} // Can be optionally applied depending on the case
};
// If there are no additional params, you can call as: bool isAllowed = BotManager.DetectPage(request, response);
bool isAllowed = BotManager.DetectPage(request, response, params);
if (!isAllowed) {
// No additional processing needed when detected (automatic Redirect)
return;
}
// Process normal request
}
}
}
Applying API Request Detection
Call BotManager.DetectApi() to apply macro detection in REST API requests.
Code Example:
using BotManagerDotNetAgent.Domain;
using System.Collections.Generic;
namespace MyApplication
{
public class ExampleApiHandler {
public void HandleApiRequest(object request, object response) {
// When passing customId
var params = new Dictionary<string, string> {
{"customId", "exampleCustomId"} // Can be optionally applied depending on the case
};
// If there are no additional params, you can call as: bool isAllowed = BotManager.DetectApi(request, response);
bool isAllowed = BotManager.DetectApi(request, response, params);
if (!isAllowed) {
// No additional processing needed when detected (automatic Redirect)
return;
}
// Process normal request
}
}
}
Method Types
DetectPage Method
DetectPage is used when processing page-level requests from browsers.
Description:
- For detected requests, the server performs redirect through the
Locationfield in HTTP response headers, which is an HTTP standard redirect method supported by all browsers. - This method is designed to fit the general browser request processing flow because it causes page transitions.
Features:
- Mainly operates when pages load, and browsers check the
Locationvalue returned from the server and automatically perform redirect. - Additionally, detection works without client-side configuration, so it can be easily applied.
Method Signature:
// Using only Request and Response
bool isAllowed = BotManager.DetectPage(request, response);
// Can pass additional parameters
bool isAllowed = BotManager.DetectPage(request, response, params);
Parameters:
request: Client request object (HttpRequest | HttpListenerRequest)response: Server response object (HttpResponse | HttpListenerResponse)params: Additional information needed for detection (Dictionary<string, string> format)- Example:
{ "tenantId": "exampleTenant", "domainName": "example.com", "customId": "user123" }
- Example:
Return Value:
true: Detection passed, can continue processing requestfalse: Detection blocked, redirect is automatically performed
DetectApi Method
DetectApi is used when processing asynchronous API calls (e.g., XMLHttpRequest, fetch) from browsers.
Description:
- For detected requests, the server adds the agreed key
X-BotManager-Locationto response headers to deliver redirect information. DetectApiis designed to work appropriately even when browsers call APIs asynchronously.
Important Notes:
- For asynchronous API calls, browsers do not automatically handle redirects through
Locationheaders, so it must be handled manually on the client side. - For this,
botmanager-browser-agentmust be applied to the browser.botmanager-browser-agenthooks asynchronous calls (xhr,fetch) in the browser to detect theX-BotManager-Locationheader and perform appropriate redirects on the client side.
- In environments where
botmanager-browser-agentis not applied,DetectApimay not work properly.
Method Signature:
// Using only Request and Response
bool isAllowed = BotManager.DetectApi(request, response);
// Can pass additional parameters
bool isAllowed = BotManager.DetectApi(request, response, params);
Parameters:
request: Client request object (HttpRequest | HttpListenerRequest)response: Server response object (HttpResponse | HttpListenerResponse)params: Additional information needed for detection (Dictionary<string, string> format)- Example:
{ "tenantId": "exampleTenant", "domainName": "example.com", "customId": "user123" }
- Example:
Return Value:
true: Detection passed, can continue processing requestfalse: Detection blocked,X-BotManager-Locationheader is added to response (handled by Browser Agent)