Skip to content

Instantly share code, notes, and snippets.

@johnathan-sewell
Created January 13, 2011 22:03
Show Gist options
  • Save johnathan-sewell/778715 to your computer and use it in GitHub Desktop.
Save johnathan-sewell/778715 to your computer and use it in GitHub Desktop.
Enables you to use relative paths with EPiServer VirtualPathVersioningProvider
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;
}
}
}
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