Exemplo n.º 1
0
        private PageRenderingResult RenderPage(string url, out string responseBody, out string errorMessage)
        {
            if (!url.StartsWith("http"))
            {
                url = UrlUtils.Combine(_serverUrl, url);
            }

            // Marking the link as valid, so it won't be shown multiple places and there won't be any additional requests
            _brokenLinks.TryAdd(url, BrokenLinkType.None);

            var result = HttpRequestHelper.RenderPage(url, out responseBody, out errorMessage);

            if (result == PageRenderingResult.NotFound)
            {
                _brokenLinks.TryAdd(url, BrokenLinkType.Relative);
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method will check a url to see that it does not return server or protocol errors
        /// </summary>
        /// <param name="url">The path to check</param>
        /// <returns></returns>
        private BrokenLinkType ValidateByRequest(RequestValidationInfo rvi)
        {
            string url = rvi.Url;

            // Allowing only one request to the same hostname at a time. Along with cache also ensures that the same url won't be requested to twice
            //object hostNameSyncRoot = GetHostNameSyncObject(rvi.Hostname);

            // lock (hostNameSyncRoot)
            {
                BrokenLinkType cachedResult;
                if (_brokenLinks.TryGetValue(url, out cachedResult))
                {
                    return(cachedResult);
                }

                bool success = HttpRequestHelper.MakeHeadRequest(url);

                var result = success ? BrokenLinkType.None : rvi.LinkType;
                SaveLinkCheckResult(url, result);

                return(result);
            }
        }