I just had this problem, and for now am going with create a special MapPath variant that corresponds to my rewrite rule.
So either something like this:
string MapTheme(string themeName)
{
return Path.Combine(Server.MapPath("/legacy"), themeName)
}
Or, if you prefer:
string MapThemePath(string themeUrl)
{
Match m = Regex.Match("^themes/(.*)");
if (!m.Success)
throw new ArgumentException();
string themeName = m.Groups[1].Value;
return Path.Combine(Server.MapPath("/legacy"), themeName)
}
Or generalize:
string MyMapPath(string url)
{
Match m = Regex.Match("^themes/(.*)");
if (m.Success)
{
string themeName = m.Groups[1].Value;
return Path.Combine(Server.MapPath("/legacy"), themeName)
}
else if (itsAnotherSpecialRewriteCase)
{
return doSomeSimilarTransformation();
}
// ...
else
{
// Handle non-rewritten URLs
return Server.MapPath(url);
}
}
I don't especially like this, because it violates "do not repeat yourself".