コード例 #1
0
        public StaticRobotsTxtProvider(RobotsTxtOptions options)
        {
            var content = options.Build().ToString()?.TrimEnd();

            if (string.IsNullOrWhiteSpace(content))
            {
                content = "# This file didn't get any instructions so everyone is allowed";
            }

            _content = Encoding.UTF8.GetBytes(content).AsMemory();

            _maxAge = Convert.ToInt32(options.MaxAge.TotalSeconds);
        }
コード例 #2
0
        private async Task BuildRobotsTxt(HttpContext context)
        {
            var sb = _options.Build();

            var output = sb.ToString()?.TrimEnd();

            if (string.IsNullOrWhiteSpace(output))
            {
                output = "# This file didn't get any instructions so everyone is allowed";
            }

            var buffer = Encoding.UTF8.GetBytes(output);
            await context.Response.Body.WriteAsync(buffer, 0, buffer.Length);
        }