Example #1
0
 /// <summary>
 /// 返回一个包含内容 URL 的字符串。
 /// </summary>
 /// <param name="contentPath">内容路径。</param>
 /// <returns>一个包含内容 URL 的字符串。</returns>
 public static string MapUrl(string contentPath)
 {
     if (string.IsNullOrEmpty(contentPath))
     {
         throw new ArgumentNullException("contentPath");
     }
     return(VirtualPathUtility.Combine(HttpRuntime.AppDomainAppVirtualPath
                                       , VirtualPathUtility.ToAbsolute(contentPath, HttpRuntime.AppDomainAppVirtualPath)));
 }
Example #2
0
        /// <summary>
        /// 返回一个包含内容 URL 的字符串。
        /// </summary>
        /// <param name="contentPath">内容路径。</param>
        /// <returns>包含内容 URL 的字符串。</returns>
        public static string MapUrl(string contentPath)
        {
            if (string.IsNullOrWhiteSpace(contentPath))
            {
                throw new ArgumentNullException(nameof(contentPath));
            }
            var path = HttpRuntime.AppDomainAppVirtualPath ?? "/";

            return(VirtualPathUtility.Combine(path, VirtualPathUtility.ToAbsolute(contentPath, path)));
        }
Example #3
0
        // Assumes 'original' is NOT rooted
        string MakeRooted(string original)
        {
            string reqdir = CurrentRequestDirectory;

            if (!String.IsNullOrEmpty(reqdir))
            {
                return(VirtualPathUtility.Combine(reqdir, original));
            }
            else
            {
                return(VirtualPathUtility.Combine(HttpRuntime.AppDomainAppVirtualPath, original));
            }
        }
        public void Combine()
        {
            Assert.AreEqual("/there", VPU.Combine("/hi", "there"), "A1");
            Assert.AreEqual("/hi/you", VPU.Combine("/hi/there", "you"), "A2");
            Assert.AreEqual("/hi/there/you", VPU.Combine("/hi/there/", "you"), "A3");

            Assert.AreEqual("/there/", VPU.Combine("/hi", "there/"), "A1");
            Assert.AreEqual("/hi/you/", VPU.Combine("/hi/there", "you/"), "A2");
            Assert.AreEqual("/hi/there/you/", VPU.Combine("/hi/there/", "you/"), "A3");

            Assert.AreEqual("/there", VPU.Combine("/hi", "/there"), "A1");
            Assert.AreEqual("/you", VPU.Combine("/hi/there", "/you"), "A2");
            Assert.AreEqual("/you", VPU.Combine("/hi/there/", "/you"), "A3");
        }
        public void Combine3()
        {
            Assert.AreEqual("/", VPU.Combine("/hi/", ".."), "A1");
            Assert.AreEqual("/", VPU.Combine("/hi/there", ".."), "A2");
            Assert.AreEqual("/hi", VPU.Combine("/hi/there/", ".."), "A3");

            Assert.AreEqual("/", VPU.Combine("/hi/", "../"), "A1");
            Assert.AreEqual("/", VPU.Combine("/hi/there", "../"), "A2");
            Assert.AreEqual("/hi/", VPU.Combine("/hi/there/", "../"), "A3");

            Assert.AreEqual("/", VPU.Combine("/", "."), "A1");
            Assert.AreEqual("/", VPU.Combine("/hi", "."), "A2");
            Assert.AreEqual("/hi", VPU.Combine("/hi/", "."), "A3");

            Assert.AreEqual("/", VPU.Combine("/", "./"), "A1");
            Assert.AreEqual("/", VPU.Combine("/hi", "./"), "A2");
            Assert.AreEqual("/hi/", VPU.Combine("/hi/", "./"), "A3");

            Assert.AreEqual("/", VPU.Combine("/hi", "there/../"), "A1");
            Assert.AreEqual("/hi", VPU.Combine("/hi/there", "you/.."), "A2");

            Assert.AreEqual("/there/", VPU.Combine("/hi", "there/./"), "A1");
            Assert.AreEqual("/hi/you", VPU.Combine("/hi/there", "you/."), "A2");

            Assert.AreEqual("/blah2/", VPU.Combine("/ROOT", "/blah1/../blah2/"));
            Assert.AreEqual("/blah1/blah2/", VPU.Combine("/ROOT", "/blah1/./blah2/"));

            Assert.AreEqual("/blah1", VPU.Combine("/ROOT", "/blah1/blah2/.."));
            Assert.AreEqual("/", VPU.Combine("/ROOT", "/blah1/.."));
            Assert.AreEqual("/blah1/", VPU.Combine("/ROOT", "/blah1/blah2/../"));
            Assert.AreEqual("/", VPU.Combine("/ROOT", "/blah1/../"));

            Assert.AreEqual("/blah1", VPU.Combine("/ROOT", "/blah1/."));
            Assert.AreEqual("/", VPU.Combine("/ROOT", "/."));
            Assert.AreEqual("/blah1/", VPU.Combine("/ROOT", "/blah1/./"));
            Assert.AreEqual("/", VPU.Combine("/ROOT", "/./"));

            Assert.AreEqual("/", VPU.Combine("///hi/", ".."), "A1");
            Assert.AreEqual("/", VPU.Combine("/hi/there/me/..", ".."), "A1");
            Assert.AreEqual("/", VPU.Combine("/hi/there/../", ".."), "A1");
            Assert.AreEqual("/hi/me", VPU.Combine("/hi/there/../", "me"), "A1");
            Assert.AreEqual("/", VPU.Combine("/hi/there/../you", ".."), "A1");
            Assert.AreEqual("/hi/me", VPU.Combine("/hi/there/../you", "me"), "A1");
            Assert.AreEqual("/hi/you/me", VPU.Combine("/hi/there/../you/", "me"), "A1");
        }
        public static void Combine4_Load(Page p)
        {
            Assert.AreEqual("~", VPU.Combine("/ROOT", "~"), "/ROOT, ~");
            Assert.AreEqual("~/blah1", VPU.Combine("/ROOT", "~/blah1"), "/ROOT, ~/blah1");
            Assert.AreEqual("~/blah1/", VPU.Combine("/ROOT", "~/blah1/"));

            Assert.AreEqual("~/blah2/", VPU.Combine("/ROOT", "~/blah1/../blah2/"));
            Assert.AreEqual("~/blah1/blah2/", VPU.Combine("/ROOT", "~/blah1/./blah2/"));

            Assert.AreEqual("~/blah1", VPU.Combine("/ROOT", "~/blah1/blah2/.."));
            Assert.AreEqual("~", VPU.Combine("/ROOT", "~/blah1/.."));
            Assert.AreEqual("~/blah1/", VPU.Combine("/ROOT", "~/blah1/blah2/../"));
            Assert.AreEqual("~/", VPU.Combine("/ROOT", "~/blah1/../"));

            Assert.AreEqual("~/blah1", VPU.Combine("/ROOT", "~/blah1/."));
            Assert.AreEqual("~", VPU.Combine("/ROOT", "~/."));
            Assert.AreEqual("~/blah1/", VPU.Combine("/ROOT", "~/blah1/./"));
            Assert.AreEqual("~/", VPU.Combine("/ROOT", "~/./"));

            Assert.AreEqual("/", VPU.Combine("~/ROOT", "~/.."), "~/ROOT, ~/..");
            Assert.AreEqual("/", VPU.Combine("~/ROOT", ".."));
            Assert.AreEqual("~", VPU.Combine("~/ROOT/", ".."));
            Assert.AreEqual("~/", VPU.Combine("~/ROOT/", "../"));
            Assert.AreEqual("~/folder", VPU.Combine("~/ROOT", "folder"));
            Assert.AreEqual("~/ROOT/folder", VPU.Combine("~/ROOT/", "folder"));
            Assert.AreEqual("~/ROOT/folder/", VPU.Combine("~/ROOT/", "folder/"));

            Assert.AreEqual("/", VPU.Combine("~", ".."));
            Assert.AreEqual("~/me", VPU.Combine("~", "me"));
            Assert.AreEqual("/me", VPU.Combine("~", "../me"));
            Assert.AreEqual("~/me", VPU.Combine("~", "./me"));

            Assert.AreEqual("/me", VPU.Combine("~/..", "me"));

            Assert.AreEqual("/", VPU.Combine("~/hi/there/..", ".."), "A1");
            Assert.AreEqual("~", VPU.Combine("~/hi/there/../", ".."), "A1");
            Assert.AreEqual("/", VPU.Combine("~/hi/there/../", "../.."), "A1");
            Assert.AreEqual("~/hi/me", VPU.Combine("~/hi/there/../", "me"), "A1");
            Assert.AreEqual("~", VPU.Combine("~/hi/there/../you", ".."), "A1");
            Assert.AreEqual("~/hi/me", VPU.Combine("~/hi/there/../you", "me"), "A1");
            Assert.AreEqual("~/hi/you/me", VPU.Combine("~/hi/there/../you/", "me"), "A1");

            Assert.AreEqual(HttpRuntime.AppDomainAppVirtualPath, VPU.Combine("/ROOT", HttpRuntime.AppDomainAppVirtualPath));
            Assert.AreEqual(HttpRuntime.AppDomainAppVirtualPath, VPU.Combine("~/ROOT", HttpRuntime.AppDomainAppVirtualPath));
        }
Example #7
0
        public virtual bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (!SecurityTrimmingEnabled)
            {
                return(true);
            }

            /* The node is accessible (according to msdn2) if:
             *
             * 1. The Roles exists on node and the current user is in at least one of the specified roles.
             *
             * 2. The current thread has an associated WindowsIdentity that has file access to the requested URL and
             * the URL is located within the directory structure for the application.
             *
             * 3. The current user is authorized specifically for the requested URL in the authorization element for
             * the current application and the URL is located within the directory structure for the application.
             */

            /* 1. */
            IList roles = node.Roles;

            if (roles != null && roles.Count > 0)
            {
                foreach (string rolename in roles)
                {
                    if (rolename == "*" || context.User.IsInRole(rolename))
                    {
                        return(true);
                    }
                }
            }

            /* 2. */
            /* XXX */

            /* 3. */
            string url = node.Url;

            if (!String.IsNullOrEmpty(url))
            {
                // TODO check url is located within the current application

                if (VirtualPathUtility.IsAppRelative(url) || !VirtualPathUtility.IsAbsolute(url))
                {
                    url = VirtualPathUtility.Combine(VirtualPathUtility.AppendTrailingSlash(HttpRuntime.AppDomainAppVirtualPath), url);
                }

                AuthorizationSection config = (AuthorizationSection)WebConfigurationManager.GetSection(
                    "system.web/authorization",
                    url);
                if (config != null)
                {
                    return(config.IsValidUser(context.User, context.Request.HttpMethod));
                }
            }

            return(false);
        }
 public void Combine2()
 {
     VPU.Combine("something", null);
 }
 public void Combine1()
 {
     VPU.Combine(null, "something");
 }
 public void Combine_ArgException8()
 {
     VPU.Combine("/ROOT", "./..");
 }
 /* stack trace is:
  * at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)
  * at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
  * at MonoTests.System.Web.VirtualPathUtilityTest.Combine()
  */
 public void Combine_ArgException5()
 {
     Assert.AreEqual("/hi", VPU.Combine("/hi", ""), "A1");
 }
 /* stack trace is:
  * at System.Web.VirtualPath.Create(String virtualPath, VirtualPathOptions options)
  * at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
  * at MonoTests.System.Web.VirtualPathUtilityTest.Combine()
  */
 public void Combine_ArgException4()
 {
     Assert.AreEqual("/you", VPU.Combine("", "you"), "A1");
 }
 public void Combine_ArgException3()
 {
     Assert.AreEqual("hi/there", VPU.Combine(null, "there"), "A1");
 }
 public void Combine_ArgException2_3()
 {
     Assert.AreEqual("hi/there", VPU.Combine("/../hi", null), "A1");
 }
 // The relative virtual path 'hi/there' is not allowed here.
 public void Combine_ArgException2_2()
 {
     Assert.AreEqual("hi/there", VPU.Combine("hi/there", "/dir"), "A1");
 }
 // The relative virtual path 'hi/there' is not allowed here.
 public void Combine_ArgException1()
 {
     Assert.AreEqual("hi/there/you", VPU.Combine("hi/there", "you"), "A1");
 }