BaseParser.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // System.Web.UI.BaseParser.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc. (http://www.ximian.com)
  9. //
  10. using System.IO;
  11. using System.Web;
  12. using System.Web.Util;
  13. namespace System.Web.UI
  14. {
  15. public class BaseParser
  16. {
  17. private HttpContext context;
  18. private string baseDir;
  19. private string baseVDir;
  20. private string vPath;
  21. internal string MapPath (string path)
  22. {
  23. return MapPath (path, true);
  24. }
  25. internal string MapPath (string path, bool allowCrossAppMapping)
  26. {
  27. if (context == null)
  28. throw new HttpException ("context is null!!");
  29. return context.Request.MapPath (path, context.Request.ApplicationPath, allowCrossAppMapping);
  30. }
  31. internal string PhysicalPath (string path)
  32. {
  33. if (Path.DirectorySeparatorChar != '/')
  34. path = path.Replace ('/', '\\');
  35. return Path.Combine (BaseDir, path);
  36. }
  37. internal HttpContext Context
  38. {
  39. get {
  40. return context;
  41. }
  42. set {
  43. context = value;
  44. }
  45. }
  46. internal string BaseDir
  47. {
  48. get {
  49. if (baseDir == null)
  50. baseDir = MapPath (BaseVirtualDir, false);
  51. return baseDir;
  52. }
  53. }
  54. internal string BaseVirtualDir
  55. {
  56. get {
  57. if (baseVDir == null)
  58. baseVDir = UrlUtils.GetDirectory (context.Request.FilePath);
  59. return baseVDir;
  60. }
  61. }
  62. internal string CurrentVirtualPath
  63. {
  64. get {
  65. return vPath;
  66. }
  67. }
  68. }
  69. }