Created
January 13, 2011 22:03
-
-
Save johnathan-sewell/778715 to your computer and use it in GitHub Desktop.
Enables you to use relative paths with EPiServer VirtualPathVersioningProvider
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
using System; | |
using System.Collections.Specialized; | |
using System.IO; | |
using System.Web.Hosting; | |
namespace EPiServer.Extensions | |
{ | |
internal static class VirtualPathProviderExtensions | |
{ | |
public static NameValueCollection FixPhysicalPath(this NameValueCollection configParameters) | |
{ | |
var physicalPath = configParameters["physicalPath"] ?? String.Empty; | |
if (physicalPath.StartsWith("~")) | |
{ | |
var rootDirectory = (HostingEnvironment.MapPath("~/") ?? Environment.CurrentDirectory).Replace("/", "\\").TrimEnd('\\'); | |
physicalPath = physicalPath.TrimStart('~', '\\').Replace("/", "\\"); | |
while (physicalPath.StartsWith("..")) | |
{ | |
rootDirectory = rootDirectory.Substring(0, rootDirectory.LastIndexOf("\\")).TrimEnd('\\'); | |
physicalPath = physicalPath.TrimStart('.'); | |
physicalPath = physicalPath.TrimStart('\\'); | |
} | |
physicalPath = Path.Combine(rootDirectory, physicalPath); | |
configParameters["physicalPath"] = physicalPath; | |
} | |
return configParameters; | |
} | |
} | |
} |
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
using System.Collections.Specialized; | |
namespace EPiServer.Extensions | |
{ | |
public class VirtualPathVersioningProvider : EPiServer.Web.Hosting.VirtualPathVersioningProvider | |
{ | |
public VirtualPathVersioningProvider(string name, NameValueCollection configParameters) | |
: base(name, configParameters.FixPhysicalPath()) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment