Exemple #1
0
        public static string MapPath(this PlatformServices services, string path)
        {
            var result = path ?? string.Empty;

            if (services.IsPathMapped(path) == false)
            {
                var wwwroot = services.WwwRoot();
                if (result.StartsWith("~", StringComparison.Ordinal))
                {
                    result = result.Substring(1);
                }
                if (result.StartsWith("/", StringComparison.Ordinal))
                {
                    result = result.Substring(1);
                }
                if (IsWindowRunTime())
                {
                    result = Path.Combine(wwwroot, result.Replace('/', '\\'));
                }
                else
                {
                    result = Path.Combine(wwwroot, result.Replace('\\', '/'));
                }
            }

            return(result);
        }
    public static string UnmapPath(this PlatformServices services, string path)
    {
        var result = path ?? string.Empty;

        if (services.IsPathMapped(path))
        {
            var wwwroot = services.WwwRoot();
            result = result.Remove(0, wwwroot.Length);
            result = result.Replace('\\', '/');
            result = (result.StartsWith("/", StringComparison.Ordinal) ? "~" : "~/") + result;
        }
        return(result);
    }