본문으로 건너뛰기

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 Location field 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 Location value 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" }

Return Value:

  • true: Detection passed, can continue processing request
  • false: 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-Location to response headers to deliver redirect information.
  • DetectApi is designed to work appropriately even when browsers call APIs asynchronously.

Important Notes:

  • For asynchronous API calls, browsers do not automatically handle redirects through Location headers, so it must be handled manually on the client side.
  • For this, botmanager-browser-agent must be applied to the browser.
    • botmanager-browser-agent hooks asynchronous calls (xhr, fetch) in the browser to detect the X-BotManager-Location header and perform appropriate redirects on the client side.
  • In environments where botmanager-browser-agent is not applied, DetectApi may 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" }

Return Value:

  • true: Detection passed, can continue processing request
  • false: Detection blocked, X-BotManager-Location header is added to response (handled by Browser Agent)