diff --git a/src/lib/MBS.Web/Control.cs b/src/lib/MBS.Web/Control.cs index 8286683..237e65e 100644 --- a/src/lib/MBS.Web/Control.cs +++ b/src/lib/MBS.Web/Control.cs @@ -13,6 +13,7 @@ public abstract class Control : IWebHandler } public Dictionary PathVariables { get; } = new Dictionary(); + public bool Visible { get; set; } = true; public Control(Dictionary? pathVariables = null) { @@ -41,18 +42,26 @@ public abstract class Control : IWebHandler private bool _initted = false; protected void EnsureInitialized() { - if (_initted) return; - InitializeInternal(); - _initted = true; + if (!_initted) + { + InitializeInternal(); + _initted = true; + } + PersistentInitializeInternal(); } protected virtual void InitializeInternal() { } + + protected virtual void PersistentInitializeInternal() + { + } protected virtual void RenderBeginTag(XmlWriter writer) { EnsureInitialized(); + writer.WriteStartElement(TagName); bool classListWritten = false; @@ -83,6 +92,8 @@ public abstract class Control : IWebHandler public void Render(XmlWriter writer) { + if (!Visible) return; + RenderBeginTag(writer); RenderContents(writer); RenderEndTag(writer); @@ -92,6 +103,7 @@ public abstract class Control : IWebHandler { context.Response.ContentType = "application/xhtml+xml"; + EnsureInitialized(); OnInit(new RenderEventArgs(context)); XmlWriter writer = XmlWriter.Create(context.Response.Stream); diff --git a/src/lib/MBS.Web/UI/Literal.cs b/src/lib/MBS.Web/UI/Literal.cs index 6def7c0..31b4dcb 100644 --- a/src/lib/MBS.Web/UI/Literal.cs +++ b/src/lib/MBS.Web/UI/Literal.cs @@ -31,7 +31,7 @@ public class Literal : Control public bool UseMarkup { get; set; } = true; public string Content { get; set; } = String.Empty; - public Literal() + public Literal() { } public Literal(string content) diff --git a/src/lib/MBS.Web/UI/WebPage.cs b/src/lib/MBS.Web/UI/WebPage.cs index 6583e25..8310f24 100644 --- a/src/lib/MBS.Web/UI/WebPage.cs +++ b/src/lib/MBS.Web/UI/WebPage.cs @@ -19,15 +19,10 @@ public class WebPage : Control { } - protected override string TagName => "html"; - protected override void RenderBeginTag(XmlWriter writer) + protected override void PersistentInitializeInternal() { - EnsureInitialized(); - writer.WriteStartElement(TagName, "http://www.w3.org/1999/xhtml"); - } - - protected override void RenderContents(XmlWriter writer) - { + base.PersistentInitializeInternal(); + Controls.Clear(); CreateChildControls(); @@ -38,7 +33,17 @@ public class WebPage : Control ChildControlsCreated = true; } */ + } + protected override string TagName => "html"; + protected override void RenderBeginTag(XmlWriter writer) + { + EnsureInitialized(); + writer.WriteStartElement(TagName, "http://www.w3.org/1999/xhtml"); + } + + protected override void RenderContents(XmlWriter writer) + { writer.WriteStartElement("head"); writer.WriteElementString("title", "Mocha Application"); diff --git a/src/lib/MBS.Web/WebServer.cs b/src/lib/MBS.Web/WebServer.cs index d4a4ca3..81907dc 100644 --- a/src/lib/MBS.Web/WebServer.cs +++ b/src/lib/MBS.Web/WebServer.cs @@ -168,6 +168,14 @@ public class WebServer string requestMethod = lineParts[0]; string path = lineParts[1]; + if (path.Length > 1) + { + if (path.EndsWith("/")) + { + path = path.Substring(0, path.Length - 1); + } + } + string version = lineParts[2]; WebHeaderCollection headers = new WebHeaderCollection(); @@ -235,7 +243,8 @@ public class WebServer if (cookieValue == "") { - cookieValue = "0068F5AD24A89AB4AFCC4057F619EADF.authgwy-prod-mzzygbiy.prod-ui-auth.pr502.cust.pdx.wd"; + // 0068F5AD24A89AB4AFCC4057F619EADF + cookieValue = (Guid.NewGuid()).ToString("N").ToUpper() + ".authgwy-prod-mzzygbiy.prod-ui-auth.pr502.cust.pdx.wd"; } bool found = false;