RobotsGroup Class

Represents a group of directives in a robots.txt file that applies to one or more user-agents.

public sealed class RobotsGroup

Remarks

A group consists of one or more User-agent lines followed by Allow, Disallow, and optional Crawl-delay directives.

Properties

NameDescription
CrawlDelayGets the crawl delay specified by a Crawl-delay directive in this group, or null if none was specified.
RulesGets the ordered list of Allow and Disallow rules in this group.
UserAgentsGets the user-agent tokens this group applies to (e.g. "Googlebot", "*").

CrawlDelay

RobotsGroup.cs

Gets the crawl delay specified by a Crawl-delay directive in this group, or null if none was specified.

public TimeSpan? CrawlDelay { get; }

Property value

TimeSpan?

Gets the ordered list of Allow and Disallow rules in this group.

public IReadOnlyList<RobotsRule> Rules { get; }

UserAgents

RobotsGroup.cs

Gets the user-agent tokens this group applies to (e.g. "Googlebot", "*").

public IReadOnlyList<string> UserAgents { get; }

Property value

IReadOnlyList<string>

Methods

NameDescription
IsAllowed(ReadOnlySpan<char>)Determines whether the given path is allowed by the rules in this group.
IsAllowed(string)Determines whether the given path is allowed by the rules in this group.
Matches(string)Determines whether this group applies to the given userAgent.
ToString()Returns a string that represents the current object.

IsAllowed overloads

IsAllowed(ReadOnlySpan<char>)

RobotsGroup.cs

Determines whether the given path is allowed by the rules in this group.

public bool IsAllowed(ReadOnlySpan<char> path)
Parameters
path ReadOnlySpan<char>
Returns

bool

IsAllowed(string)

RobotsGroup.cs

Determines whether the given path is allowed by the rules in this group.

public bool IsAllowed(string path)
Parameters
path string
The URL path (and optional query string) to check.
Returns

bool true if access is allowed; false if it is disallowed.

Remarks

The most specific (longest RobotsRule.Value) matching rule wins. When two matching rules have equal specificity, RobotsRuleKind.Allow takes precedence.

An empty Disallow path is treated as "allow all" and only matches when no other rule matches. If no rule matches the path, access is allowed.

Matches(string)

RobotsGroup.cs

Determines whether this group applies to the given userAgent.

public bool Matches(string userAgent)

Parameters

userAgent string

Returns

bool

Remarks

The comparison is case-insensitive. A group with user-agent * matches any agent.

ToString()

RobotsGroup.cs

Returns a string that represents the current object.

public override string ToString()

Returns

string A string that represents the current object.