public string GetRobotsContent(string robotsKey) { try { // Always try to retrieve from cache first var cache = CacheManager.Get(GetCacheKey(robotsKey)); if (cache != null) { return((cache as RobotsTxtData).RobotsTxtContent); } using (var robotsDataStore = typeof(RobotsTxtData).GetStore()) { // Look up the content in the DDS var result = robotsDataStore.Find <RobotsTxtData>("Key", robotsKey).FirstOrDefault(); if (result == null) { // OK there is nothing found so create some default content result = new RobotsTxtData { Key = robotsKey, RobotsTxtContent = GetDefaultRobotsContent() }; SaveRobotsContent(result.RobotsTxtContent, robotsKey); } // Ensure we cache the result using the EPiServer cache manager to ensure // everything works in a load balanced/mirrored environement CacheManager.Insert(GetCacheKey(robotsKey), result); return(result.RobotsTxtContent); } } catch (Exception ex) { logger.Error("Error getting robots.txt content, returning default robots.txt content", ex); return(GetDefaultRobotsContent()); } }
public string GetRobotsContent(string robotsKey) { try { // Always try to retrieve from cache first var cache = CacheManager.Get(GetCacheKey(robotsKey)); if (cache != null) return (cache as RobotsTxtData).RobotsTxtContent; using (var robotsDataStore = typeof(RobotsTxtData).GetStore()) { // Look up the content in the DDS var result = robotsDataStore.Find<RobotsTxtData>("Key", robotsKey).FirstOrDefault(); if (result == null) { // OK there is nothing found so create some default content result = new RobotsTxtData { Key = robotsKey, RobotsTxtContent = GetDefaultRobotsContent() }; SaveRobotsContent(result.RobotsTxtContent, robotsKey); } // Ensure we cache the result using the EPiServer cache manager to ensure // everything works in a load balanced/mirrored environement CacheManager.Add(GetCacheKey(robotsKey), result); return result.RobotsTxtContent; } } catch (Exception ex) { logger.Error("Error getting robots.txt content, returning default robots.txt content", ex); return GetDefaultRobotsContent(); } }