public static string GetBlogSubfolderFromRequest(string rawUrl, string applicationPath)
{
if(rawUrl == null)
throw new ArgumentNullException("rawUrl", "The path cannot be null.");
if(applicationPath == null)
throw new ArgumentNullException("applicationPath", "The app should not be null.");
// The {0} represents a potential virtual directory
string urlPatternFormat = "{0}/(?<app>.*?)/";
//Remove any / from App.
string cleanApp = "/" + StripSurroundingSlashes(applicationPath);
if(cleanApp == "/")
cleanApp = string.Empty;
string appRegex = Regex.Escape(cleanApp);
string urlRegexPattern = string.Format(CultureInfo.InvariantCulture, urlPatternFormat, appRegex);
Regex urlRegex = new Regex(urlRegexPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
Match match = urlRegex.Match(rawUrl);
if(match.Success)
{
return match.Groups["app"].Value;
}
else
{
return string.Empty;
}
}