/// <summary>
        /// Determines whether node is accessible to user.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        /// <param name="node">The node.</param>
        /// <returns>
        ///     <c>true</c> if accessible to user; otherwise, <c>false</c>.
        /// </returns>
        public bool IsAccessibleToUser(ISiteMap siteMap, ISiteMapNode node)
        {
            // If we have roles assigned, check them against the roles defined in the sitemap
            if (node.Roles != null && node.Roles.Count > 0)
            {
                var context = mvcContextFactory.CreateHttpContext();

                // if there is an authenticated user and the role allows anyone authenticated ("*"), show it
                if ((context.User.Identity.IsAuthenticated) && node.Roles.Contains("*"))
                {
                    return(true);
                }

                // if there is no user, but the role allows unauthenticated users ("?"), show it
                if ((!context.User.Identity.IsAuthenticated) && node.Roles.Contains("?"))
                {
                    return(true);
                }

                // if the user is in one of the listed roles, show it
                if (node.Roles.OfType <string>().Any(role => context.User.IsInRole(role)))
                {
                    return(true);
                }

                // if we got this far, deny showing
                return(false);
            }

            // Everything seems OK...
            return(true);
        }
        public virtual string GenerateKey()
        {
            var context = mvcContextFactory.CreateHttpContext();
            var builder = new StringBuilder();

            builder.Append("sitemap://");
            builder.Append(context.Request.Url.DnsSafeHost);
            builder.Append("/");
            return(builder.ToString());
        }
        protected virtual string GetImplicitResourceString(string attributeName, string implicitResourceKey, string classKey)
        {
            if (attributeName == null)
            {
                throw new ArgumentNullException("attributeName");
            }
            string globalResourceObject = null;

            if (!string.IsNullOrEmpty(implicitResourceKey))
            {
                var httpContext = mvcContextFactory.CreateHttpContext();
                try
                {
                    globalResourceObject = httpContext.GetGlobalResourceObject(classKey, implicitResourceKey + "." + attributeName) as string;
                }
                catch
                {
                }
            }
            return(globalResourceObject);
        }
Beispiel #4
0
        // methods - ISiteMapCacheKeyGenerator Members
        public virtual string GenerateKey()
        {
            var context = mvcContextFactory.CreateHttpContext();
            var builder = new StringBuilder();

            builder.Append("sitemap://");
            builder.Append(context.Request.Url.DnsSafeHost);
            builder.Append("/?sessionId=");
            builder.Append(context.Session.SessionID);

            LogUtility.Logger.Debug($"key = {builder.ToString()}");

            return(builder.ToString());
        }
Beispiel #5
0
        public string ResolveServerUrl(string serverUrl, bool forceHttps)
        {
            // Is it already an absolute Url?
            if (serverUrl.IndexOf("://") > -1)
            {
                return(serverUrl);
            }

            // Start by fixing up the Url an Application relative Url
            string newUrl = ResolveUrl(serverUrl);

            // Due to URL rewriting, cloud computing (i.e. Azure)
            // and web farms, etc., we have to be VERY careful about what
            // we consider the incoming URL.  We want to see the URL as it would
            // appear on the public-facing side of the hosting web site.
            // HttpRequest.Url gives us the internal URL in a cloud environment,
            // So we use a variable that (at least from what I can tell) gives us
            // the public URL:
            Uri originalUri = null;
            var httpContext = mvcContextFactory.CreateHttpContext();

            if (httpContext.Request.Headers["Host"] != null)
            {
                string scheme = httpContext.Request.Headers["HTTP_X_FORWARDED_PROTO"]
                                ?? httpContext.Request.Url.Scheme;
                originalUri = new Uri(scheme + Uri.SchemeDelimiter + httpContext.Request.Headers["Host"]);
            }
            else
            {
                originalUri = httpContext.Request.Url;
            }

            newUrl = (forceHttps ? "https" : originalUri.Scheme) +
                     "://" + originalUri.Authority + newUrl;

            if (newUrl.EndsWith("//"))
            {
                newUrl = newUrl.Substring(0, newUrl.Length - 2);
            }

            // Strip off the application root
            newUrl = new Uri(newUrl).GetLeftPart(UriPartial.Authority);

            return(newUrl);
        }
        /// <summary>
        /// Determines whether node is accessible to user.
        /// </summary>
        /// <param name="siteMap">The site map.</param>
        /// <param name="node">The node.</param>
        /// <returns>
        ///     <c>true</c> if accessible to user; otherwise, <c>false</c>.
        /// </returns>
        public bool IsAccessibleToUser(ISiteMap siteMap, ISiteMapNode node)
        {
            // Clickable? Always accessible.
            if (node.Clickable == false)
            {
                return(true);
            }

            var httpContext = mvcContextFactory.CreateHttpContext();

            // Is it an external Url?
            if (node.HasExternalUrl(httpContext))
            {
                return(true);
            }

            return(this.VerifyNode(siteMap, node, httpContext));
        }
Beispiel #7
0
        /// <summary>
        /// Retrieves a <see cref="T:MvcSiteMapProvider.ISiteMapNode"/> object that represents the currently requested page using the current <see cref="T:System.Web.HttpContext"/> object.
        /// </summary>
        /// <returns>
        /// A <see cref="T:MvcSiteMapProvider.ISiteMapNode"/> that represents the currently requested page; otherwise, null, if no corresponding <see cref="T:MvcSiteMapProvider.ISiteMapNode"/> can be found in the <see cref="T:MvcSiteMapProvider.SiteMapNode"/> or if the page context is null.
        /// </returns>
        public virtual ISiteMapNode FindSiteMapNodeFromCurrentContext()
        {
            var httpContext = mvcContextFactory.CreateHttpContext();

            return(FindSiteMapNode(httpContext));
        }