string MakeRelative(string fullUrl, string relativeTo) { if (fullUrl == relativeTo) { return(String.Empty); } if (fullUrl.IndexOf(relativeTo) != 0) { return(null); } string leftOver = fullUrl.Substring(relativeTo.Length); if (leftOver.Length > 0 && leftOver [0] == '/') { leftOver = leftOver.Substring(1); } leftOver = UrlUtils.Canonic(leftOver); if (leftOver.Length > 0 && leftOver [0] == '/') { leftOver = leftOver.Substring(1); } return(leftOver); }
public string ApplyAppPathModifier(string virtualPath) { if (virtualPath == null) { return(null); } if (virtualPath.Length == 0) { return(context.Request.RootVirtualDir); } if (UrlUtils.IsRelativeUrl(virtualPath)) { virtualPath = UrlUtils.Combine(context.Request.RootVirtualDir, virtualPath); } else if (UrlUtils.IsRooted(virtualPath)) { virtualPath = UrlUtils.Canonic(virtualPath); } bool cookieless = false; #if NET_2_0 SessionStateSection config = WebConfigurationManager.GetWebApplicationSection("system.web/sessionState") as SessionStateSection; cookieless = SessionStateModule.IsCookieLess(context, config); #else SessionConfig config = HttpContext.GetAppConfig("system.web/sessionState") as SessionConfig; cookieless = config.CookieLess; #endif if (!cookieless) { return(virtualPath); } if (app_path_mod != null && virtualPath.IndexOf(app_path_mod) < 0) { if (UrlUtils.HasSessionId(virtualPath)) { virtualPath = UrlUtils.RemoveSessionId(VirtualPathUtility.GetDirectory(virtualPath), virtualPath); } return(UrlUtils.InsertSessionId(app_path_mod, virtualPath)); } return(virtualPath); }
public string NormalizeVirtualPath(string virtualPath) { if (virtualPath == null || virtualPath.Length == 0) { virtualPath = "."; } else { virtualPath = virtualPath.Trim(); } if (virtualPath [0] == '~' && virtualPath.Length > 2 && virtualPath [1] == '/') { virtualPath = virtualPath.Substring(1); } if (System.IO.Path.DirectorySeparatorChar != '/') { virtualPath = virtualPath.Replace(System.IO.Path.DirectorySeparatorChar, '/'); } if (UrlUtils.IsRooted(virtualPath)) { virtualPath = UrlUtils.Canonic(virtualPath); } else { if (map.VirtualDirectories.Count > 0) { string root = map.VirtualDirectories [0].VirtualDirectory; virtualPath = UrlUtils.Combine(root, virtualPath); virtualPath = UrlUtils.Canonic(virtualPath); } } return(virtualPath); }