Example #1
0
        public HeaderResult CreateXRobotsTagResult(IXRobotsTagConfiguration xRobotsTagConfig,
                                                   IXRobotsTagConfiguration oldXRobotsTagConfig = null)
        {
            if (oldXRobotsTagConfig != null && oldXRobotsTagConfig.Enabled && xRobotsTagConfig.Enabled == false)
            {
                return(new HeaderResult(HeaderResult.ResponseAction.Remove, HeaderConstants.XRobotsTagHeader));
            }

            if (xRobotsTagConfig.Enabled == false)
            {
                return(null);
            }

            var sb = new StringBuilder();

            sb.Append(xRobotsTagConfig.NoIndex ? "noindex, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoFollow ? "nofollow, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoSnippet && !xRobotsTagConfig.NoIndex ? "nosnippet, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoArchive && !xRobotsTagConfig.NoIndex ? "noarchive, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoOdp && !xRobotsTagConfig.NoIndex ? "noodp, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoTranslate && !xRobotsTagConfig.NoIndex ? "notranslate, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoImageIndex ? "noimageindex" : String.Empty);
            var value = sb.ToString().TrimEnd(' ', ',');

            if (value.Length == 0)
            {
                return(null);
            }

            return(new HeaderResult(HeaderResult.ResponseAction.Set, HeaderConstants.XRobotsTagHeader, value));
        }
Example #2
0
        public HeaderResult CreateXRobotsTagResult(IXRobotsTagConfiguration xRobotsTagConfig,
            IXRobotsTagConfiguration oldXRobotsTagConfig = null)
        {
            if (oldXRobotsTagConfig != null && oldXRobotsTagConfig.Enabled && xRobotsTagConfig.Enabled == false)
            {
                return new HeaderResult(HeaderResult.ResponseAction.Remove, HeaderConstants.XRobotsTagHeader);
            }

            if (xRobotsTagConfig.Enabled == false)
            {
                return null;
            }

            var sb = new StringBuilder();
            sb.Append(xRobotsTagConfig.NoIndex ? "noindex, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoFollow ? "nofollow, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoSnippet && !xRobotsTagConfig.NoIndex ? "nosnippet, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoArchive && !xRobotsTagConfig.NoIndex ? "noarchive, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoOdp && !xRobotsTagConfig.NoIndex ? "noodp, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoTranslate && !xRobotsTagConfig.NoIndex ? "notranslate, " : String.Empty);
            sb.Append(xRobotsTagConfig.NoImageIndex ? "noimageindex" : String.Empty);
            var value = sb.ToString().TrimEnd(' ', ',');

            if (value.Length == 0) return null;

            return new HeaderResult(HeaderResult.ResponseAction.Set, HeaderConstants.XRobotsTagHeader, value);
        }
        public XRobotsTagMiddleware(AppFunc next, XRobotsTagOptions options)
            : base(next)
        {
            _config = options.Config;

            var headerGenerator = new HeaderGenerator();
            _headerResult = headerGenerator.CreateXRobotsTagResult(_config);
        }
Example #4
0
        public XRobotsTagMiddleware(AppFunc next, XRobotsTagOptions options)
            : base(next)
        {
            _config = options.Config;

            var headerGenerator = new HeaderGenerator();

            _headerResult = headerGenerator.CreateXRobotsTagResult(_config);
        }
        internal void SetXRobotsTagHeaderOverride(HttpContextBase context, IXRobotsTagConfiguration setXRobotsTagHeaderConfig)
        {
            _xRobotsValidator.Validate(setXRobotsTagHeaderConfig);
            var headerList = GetHeaderListFromContext(context);
            const string headerKey = SetXRobotsTagHeadersKey;

            if (headerList.ContainsKey(SetXRobotsTagHeadersKey))
                headerList.Remove(headerKey);

            headerList.Add(headerKey, setXRobotsTagHeaderConfig);
        }
        internal void SetXRobotsTagHeaderOverride(HttpContext context, IXRobotsTagConfiguration setXRobotsTagHeaderConfig)
        {
            _xRobotsValidator.Validate(setXRobotsTagHeaderConfig);
            var          headerList = GetHeaderListFromContext(context);
            const string headerKey  = SetXRobotsTagHeadersKey;

            if (headerList.ContainsKey(SetXRobotsTagHeadersKey))
            {
                headerList.Remove(headerKey);
            }

            headerList.Add(headerKey, setXRobotsTagHeaderConfig);
        }
        public void Validate(IXRobotsTagConfiguration xRobotsConfig)
        {
            if (!xRobotsConfig.Enabled) return;

            if (xRobotsConfig.NoArchive ||
                xRobotsConfig.NoFollow ||
                xRobotsConfig.NoImageIndex ||
                xRobotsConfig.NoIndex ||
                xRobotsConfig.NoOdp ||
                xRobotsConfig.NoSnippet ||
                xRobotsConfig.NoTranslate) return;
            throw new Exception(
                "One or more directives must be enabled when header is enabled. Enable directives or disable header.");
        }
Example #8
0
        public void Validate(IXRobotsTagConfiguration xRobotsConfig)
        {
            if (!xRobotsConfig.Enabled)
            {
                return;
            }

            if (xRobotsConfig.NoArchive ||
                xRobotsConfig.NoFollow ||
                xRobotsConfig.NoImageIndex ||
                xRobotsConfig.NoIndex ||
                xRobotsConfig.NoOdp ||
                xRobotsConfig.NoSnippet ||
                xRobotsConfig.NoTranslate)
            {
                return;
            }
            throw new Exception(
                      "One or more directives must be enabled when header is enabled. Enable directives or disable header.");
        }
Example #9
0
        internal void SetXRobotsTagHeaderOverride(IHttpContextWrapper context, IXRobotsTagConfiguration setXRobotsTagHeaderConfig)
        {
            _xRobotsValidator.Validate(setXRobotsTagHeaderConfig);

            context.GetNWebsecOverrideContext().XRobotsTag = setXRobotsTagHeaderConfig;
        }