Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotnetchris/84e7924056ff108a843d to your computer and use it in GitHub Desktop.
Save dotnetchris/84e7924056ff108a843d to your computer and use it in GitHub Desktop.
// blows up if url contains a query string
//string absoluteToUrl = Path.GetFullPath(Path.Combine(cssFilePath, relativeToCSS));
// replace with
// this is a path that is relative to the CSS file
string relativeToCSS = match.Groups[2].Value;
//prevent querystring from causing error
var pathAndQuery = relativeToCSS.Split(new[] { '?' }, 2, StringSplitOptions.RemoveEmptyEntries);
var pathOnly = pathAndQuery[0];
var queryOnly = pathAndQuery.Length == 2 ? "?" + pathAndQuery[1] : string.Empty;
// combine the relative path to the cssAbsolute
string absoluteToUrl = Path.GetFullPath(Path.Combine(cssFilePath, pathOnly));
// make this server relative
string serverRelativeUrl = context.HttpContext.RelativeFromAbsolutePath(absoluteToUrl) + queryOnly;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment