Guest User

Untitled

a guest
Jul 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.IO;
  4. using System.Web.Hosting;
  5.  
  6. namespace EPiServer.Extensions
  7. {
  8. internal static class VirtualPathProviderExtensions
  9. {
  10. public static NameValueCollection FixPhysicalPath(this NameValueCollection configParameters)
  11. {
  12. var physicalPath = configParameters["physicalPath"] ?? String.Empty;
  13.  
  14. if (physicalPath.StartsWith("~"))
  15. {
  16. var rootDirectory = (HostingEnvironment.MapPath("~/") ?? Environment.CurrentDirectory).Replace("/", "\\").TrimEnd('\\');
  17. physicalPath = physicalPath.TrimStart('~', '\\').Replace("/", "\\");
  18.  
  19. while (physicalPath.StartsWith(".."))
  20. {
  21. rootDirectory = rootDirectory.Substring(0, rootDirectory.LastIndexOf("\\")).TrimEnd('\\');
  22. physicalPath = physicalPath.TrimStart('.');
  23. physicalPath = physicalPath.TrimStart('\\');
  24. }
  25.  
  26. physicalPath = Path.Combine(rootDirectory, physicalPath);
  27.  
  28. configParameters["physicalPath"] = physicalPath;
  29. }
  30.  
  31. return configParameters;
  32. }
  33. }
  34. }
Add Comment
Please, Sign In to add comment