Beispiel #1
0
        /// <summary>
        /// This is test path.
        /// Our target is testing in core HttpRuntime.AppDomainAppVirtualPath is same to in framework GetAppDomainString(".appVPath")
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            // physic path.
            var contentRootPath = HttpContext
                                  .RequestServices
                                  .GetRequiredService <IWebHostEnvironment>()
                                  .ContentRootPath;


            var appDomainAppVirtualPath = AppDomainAppVirtualPath;

            //default appDomainAppVirtualPath is "/"
            Assert.AreEqual(appDomainAppVirtualPath, "/");

            //now change it.
            HttpContext.Request.PathBase = "/eee";

            Assert.AreEqual(HttpContext.Request.PathBase.HasValue, true);

            Assert.AreEqual(HttpContext.Request.PathBase.Value, "/eee");

            var hasValue = HttpContext.Request.PathBase.HasValue;

            //test VirtualPath.CreateNonRelativeTrailingSlash
            VirtualPath vPath = VirtualPath.CreateNonRelativeTrailingSlash(HttpContext.Request.PathBase.Value);

            Assert.AreEqual(vPath.VirtualPathString, "/eee/");
            return(View());
        }
        public ActionResult Index()
        {
            // this is a physic path of this app.
            var appPath = GetAppDomainString(".appPath");

            //
            var appVPath = GetAppDomainString(".appVPath");

            Assert.AreEqual(appVPath, "/");

            // change appVPath
            SetAppDomainString(".appVPath", "/eee");

            appVPath = GetAppDomainString(".appVPath");

            //When set this value, just set, change nothing.
            Assert.AreEqual(appVPath, "/eee");


            var nonRelativeTrailingSlash = VirtualPath.CreateNonRelativeTrailingSlash(appVPath);

            Assert.AreEqual(nonRelativeTrailingSlash.VirtualPathString, "/eee/");

            return(View());
        }