diff --git a/Ooui.AspNetCore/ElementResult.cs b/Ooui.AspNetCore/ElementResult.cs index f43d342..23234a6 100644 --- a/Ooui.AspNetCore/ElementResult.cs +++ b/Ooui.AspNetCore/ElementResult.cs @@ -7,11 +7,13 @@ namespace Ooui.AspNetCore { public class ElementResult : ActionResult { - readonly Element element; + readonly Element element; + readonly string title; - public ElementResult (Element element) + public ElementResult (Element element, string title = "") { - this.element = element; + this.element = element; + this.title = title; } public override async Task ExecuteResultAsync (ActionContext context) @@ -20,10 +22,11 @@ namespace Ooui.AspNetCore response.StatusCode = 200; response.ContentType = "text/html; charset=utf-8"; var sessionId = WebSocketHandler.BeginSession (context.HttpContext, element); - var html = Encoding.UTF8.GetBytes (UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId)); - response.ContentLength = html.Length; + var html = UI.RenderTemplate (WebSocketHandler.WebSocketPath + "?id=" + sessionId, title: title); + var htmlBytes = Encoding.UTF8.GetBytes (html); + response.ContentLength = htmlBytes.Length; using (var s = response.Body) { - await s.WriteAsync (html, 0, html.Length).ConfigureAwait (false); + await s.WriteAsync (htmlBytes, 0, htmlBytes.Length).ConfigureAwait (false); } } } diff --git a/Ooui/UI.cs b/Ooui/UI.cs index 17e6c77..213143e 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -299,9 +299,9 @@ namespace Ooui } } - public static string RenderTemplate (string webSocketPath) + public static string RenderTemplate (string webSocketPath, string title = "") { - return Template.Replace ("@WebSocketPath", webSocketPath).Replace ("@Styles", rules.ToString ()); + return Template.Replace ("@WebSocketPath", webSocketPath).Replace ("@Styles", rules.ToString ()).Replace ("@Title", title); } class DataHandler : RequestHandler diff --git a/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs b/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs index 640f9b5..3503207 100644 --- a/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs +++ b/PlatformSamples/AspNetCoreMvc/Controllers/SamplesController.cs @@ -51,7 +51,7 @@ namespace AspNetCoreMvc.Controllers if (s == null) return NotFound (); - return new ElementResult (s.CreateElement ()); + return new ElementResult (s.CreateElement (), title: s.Title + " - Ooui Samples"); } } }