Created
August 20, 2014 17:24
-
-
Save dotnetchris/84e7924056ff108a843d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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