private bool FindMatchAndReplace(String currentPath, out String newPath)
{
newPath = String.Empty;
foreach(RoutingRule rule in routingRules)
{
if (rule.CompiledRule.IsMatch(currentPath))
{
newPath = rule.CompiledRule.Replace(currentPath, rule.Replace);
//Append the query string
String queryString = HttpContext.Current.Request.Url.Query;
if (queryString.Length > 0)
{
//If we already have some query string params on the new path...
bool hasParams = (newPath.LastIndexOf("?") != -1);
if (hasParams)
{
//...make sure we append the query string nicely rather than adding another ?
queryString = queryString.Replace("?", "&");
}
newPath += queryString;
}
if (ExcludeAppPath)
{
string appPath = HttpContext.Current.Request.ApplicationPath;
if (appPath.Length > 1)
{
newPath = appPath + newPath;
}
}
return true;
}
}
return false;
}