public RobotsTxtResult GenerateRobotsTxt() { try { StringBuilder robotsOutput = new StringBuilder(); var robotsTxtArray = this.configuration .GetSection(RobotsTxtConfigurationKey) .AsEnumerable() .Where(x => !string.IsNullOrEmpty(x.Value)) .OrderBy(x => x.Key) .ToArray(); for (int i = 0; i < robotsTxtArray.Count(); i++) { robotsOutput.AppendLine(robotsTxtArray[i].Value); } var robotsResult = new RobotsTxtResult { Content = robotsOutput.ToString() }; return(robotsResult); } catch (Exception ex) { LogError(ex, nameof(GenerateRobotsTxt)); return(new RobotsTxtResult()); } }
public IActionResult Robots() { RobotsTxtResult robotsTxtResult = this.seoService.GenerateRobotsTxt(); return(Ok(robotsTxtResult.Content)); }