/// <summary> /// Resolves an absolute web path for the file path /// </summary> /// <param name="file"></param> /// <param name="http"></param> /// <returns></returns> public static string ResolveFilePath(this IClientDependencyFile file, HttpContextBase http) { var trimmedPath = file.FilePath.Trim(); if (string.IsNullOrEmpty(trimmedPath)) { throw new ArgumentException("The Path specified is null", "Path"); } if (trimmedPath.StartsWith("~/")) { return http.ResolveUrl(file.FilePath); } if (trimmedPath.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) || trimmedPath.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase)) { return file.FilePath; } var filePath = file.FilePath; if (!http.IsAbsolute(filePath)) { //get the relative path var path = http.Request.AppRelativeCurrentExecutionFilePath.Substring(0, http.Request.AppRelativeCurrentExecutionFilePath.LastIndexOf('/') + 1); filePath = http.ResolveUrl(path + filePath); } var uri = new Uri(new Uri("https://example.com"), filePath); return uri.PathAndQuery; }
public static string ResolvePath(this IClientDependencyPath path, HttpContextBase http) { if (string.IsNullOrEmpty(path.Path)) { throw new ArgumentException("The Path specified is null", "Path"); } if (path.Path.StartsWith("~/")) { return http.ResolveUrl(path.Path); } return path.Path; }