/// <summary>
        /// Ensures that the request is a document request (i.e. one that the module should handle)
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="uri"></param>
        /// <returns></returns>
        private bool EnsureDocumentRequest(HttpContextBase httpContext, Uri uri)
        {
            var maybeDoc = true;
            var lpath    = uri.AbsolutePath.ToLowerInvariant();

            // handle directory-urls used for asmx
            // legacy - what's the point really?
            if (/*maybeDoc &&*/ _globalSettings.UseDirectoryUrls)
            {
                var asmxPos = lpath.IndexOf(".asmx/", StringComparison.OrdinalIgnoreCase);
                if (asmxPos >= 0)
                {
                    // use uri.AbsolutePath, not path, 'cos path has been lowercased
                    httpContext.RewritePath(uri.AbsolutePath.Substring(0, asmxPos + 5), // filePath
                                            uri.AbsolutePath.Substring(asmxPos + 5),    // pathInfo
                                            uri.Query.TrimStart('?'));
                    maybeDoc = false;
                }
            }

            // a document request should be
            // /foo/bar/nil
            // /foo/bar/nil/
            // /foo/bar/nil.aspx
            // where /foo is not a reserved path

            // if the path contains an extension that is not .aspx
            // then it cannot be a document request
            var extension = Path.GetExtension(lpath);

            if (maybeDoc && extension.IsNullOrWhiteSpace() == false && extension != ".aspx")
            {
                maybeDoc = false;
            }

            // at that point, either we have no extension, or it is .aspx

            // if the path is reserved then it cannot be a document request
            if (maybeDoc && _globalSettings.IsReservedPathOrUrl(lpath, httpContext, _combinedRouteCollection.Value))
            {
                maybeDoc = false;
            }

            //NOTE: No need to warn, plus if we do we should log the document, as this message doesn't really tell us anything :)
            //if (!maybeDoc)
            //{
            //    Logger.Warn<UmbracoModule>("Not a document");
            //}

            return(maybeDoc);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the current request is reserved based on the route table and
        /// whether the specified URL is reserved or is inside a reserved path.
        /// </summary>
        /// <param name="globalSettings"></param>
        /// <param name="url"></param>
        /// <param name="httpContext"></param>
        /// <param name="routes">The route collection to lookup the request in</param>
        /// <returns></returns>
        internal static bool IsReservedPathOrUrl(this IGlobalSettings globalSettings, string url, HttpContextBase httpContext, RouteCollection routes)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }
            if (routes == null)
            {
                throw new ArgumentNullException(nameof(routes));
            }

            //check if the current request matches a route, if so then it is reserved.
            var route = routes.GetRouteData(httpContext);

            if (route != null)
            {
                return(true);
            }

            //continue with the standard ignore routine
            return(globalSettings.IsReservedPathOrUrl(url));
        }