Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Add Comment
Please, Sign In to add comment