PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Web/Controls/RewriteFormHtmlTextWriter.cs

#
C# | 88 lines | 49 code | 8 blank | 31 comment | 9 complexity | 4f7204e45a544a44823ed59781623740 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace BlogEngine.Core.Web.Controls
  2. {
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.UI;
  6. /// <summary>
  7. /// The RewriteFormHtmlTextWriter class implements Form action tag rewriting for rewritten pages
  8. /// on Mono.
  9. /// </summary>
  10. public class RewriteFormHtmlTextWriter : HtmlTextWriter
  11. {
  12. #region Constructors and Destructors
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="RewriteFormHtmlTextWriter"/> class.
  15. /// </summary>
  16. /// <param name="writer">
  17. /// The writer.
  18. /// </param>
  19. public RewriteFormHtmlTextWriter(Html32TextWriter writer)
  20. : base(writer)
  21. {
  22. this.InnerWriter = writer.InnerWriter;
  23. }
  24. /// <summary>
  25. /// Initializes a new instance of the <see cref="RewriteFormHtmlTextWriter"/> class.
  26. /// </summary>
  27. /// <param name="writer">
  28. /// The writer.
  29. /// </param>
  30. public RewriteFormHtmlTextWriter(TextWriter writer)
  31. : base(writer)
  32. {
  33. this.InnerWriter = writer;
  34. }
  35. #endregion
  36. #region Public Methods
  37. /// <summary>
  38. /// Writes the specified markup attribute and value to the output stream, and, if specified, writes the value encoded.
  39. /// </summary>
  40. /// <param name="name">
  41. /// The markup attribute to write to the output stream.
  42. /// </param>
  43. /// <param name="value">
  44. /// The value assigned to the attribute.
  45. /// </param>
  46. /// <param name="encode">
  47. /// true to encode the attribute and its assigned value; otherwise, false.
  48. /// </param>
  49. public override void WriteAttribute(string name, string value, bool encode)
  50. {
  51. // Mono has issues identifying relative paths when the url is rewritten,
  52. // so we need to place the full path in the form tag's action attribute
  53. // or postbacks won't work in rewritten pages.
  54. if (Utils.IsMono)
  55. {
  56. if (name == "action")
  57. {
  58. if (HttpContext.Current.Items["ActionAlreadyWritten"] == null)
  59. {
  60. value = Utils.AbsoluteWebRoot + value;
  61. HttpContext.Current.Items["ActionAlreadyWritten"] = true;
  62. }
  63. }
  64. }
  65. else
  66. {
  67. if (name == "action")
  68. {
  69. if (HttpContext.Current.Items["ActionAlreadyWritten"] == null)
  70. {
  71. value = HttpContext.Current.Request.RawUrl;
  72. HttpContext.Current.Items["ActionAlreadyWritten"] = true;
  73. }
  74. }
  75. }
  76. base.WriteAttribute(name, value, encode);
  77. }
  78. #endregion
  79. }
  80. }