diff --git a/WebServer.Test/Views/localhost/Index.cshtml b/WebServer.Test/Views/localhost/Index.cshtml new file mode 100644 index 0000000..42d3c18 --- /dev/null +++ b/WebServer.Test/Views/localhost/Index.cshtml @@ -0,0 +1,8 @@ +@using RazorLight +@inherits TemplatePage +@{ + Layout = "/_Layout.cshtml"; + ViewBag.Title = "Home"; +} +

Hello!

+How you doing? \ No newline at end of file diff --git a/WebServer.Test/Views/localhost/Test.cshtml b/WebServer.Test/Views/localhost/Test.cshtml index efbf544..7f525df 100644 --- a/WebServer.Test/Views/localhost/Test.cshtml +++ b/WebServer.Test/Views/localhost/Test.cshtml @@ -1 +1,6 @@ -Hello World! \ No newline at end of file +@using RazorLight +@inherits TemplatePage +@{ + Layout = "_Layout.cshtml"; +} +Hello World! \ No newline at end of file diff --git a/WebServer.Test/Views/localhost/_Layout.cshtml b/WebServer.Test/Views/localhost/_Layout.cshtml index adf733e..404d568 100644 --- a/WebServer.Test/Views/localhost/_Layout.cshtml +++ b/WebServer.Test/Views/localhost/_Layout.cshtml @@ -1,29 +1,19 @@ - +@using RazorLight; +@using WebServer.Extensions; +@{ + ViewBag.Title = (ExpandoObjectExt.TryGetProperty(ViewBag, "Title", out object title) + ? $"{title} - " : string.Empty + ) + "MySite"; +} + + @ViewBag.Title - - - - @RenderSection("Styles", required: false) - + + @RenderSection("Styles", required: false) @RenderBody() diff --git a/WebServer.Test/Views/localhost/_StatusPage.cshtml b/WebServer.Test/Views/localhost/_StatusPage.cshtml index dfb1c7f..723acac 100644 --- a/WebServer.Test/Views/localhost/_StatusPage.cshtml +++ b/WebServer.Test/Views/localhost/_StatusPage.cshtml @@ -1,16 +1,19 @@ -@using RazorLight -@inherits TemplatePage -@model WebServer.Models.StatusPageModel +@using System; +@using RazorLight; +@inherits TemplatePage; +@model WebServer.Models.StatusPageModel; @{ - Layout = @"_Layout.cshtml"; - ViewBag.Title = $"{Model.StatusCodeAsUShort} - {Model.Header}"; + Layout = @"/_Layout.cshtml"; + ViewBag.Title = Model.Header; + + // Uncomment to show a test exception + //try { throw new Exception("Test Exception thrown in _StatusPage.cshtml"); } catch (Exception ex) { Model.Exception ??= ex; } } -
-
@Model.Header
- @Model.Details - @if (Model.Exception != null) { -
-
@Model.Exception
-
- } -
\ No newline at end of file + +
@Model.Header
+@Model.Details +@if (Model.Exception != null) { +
+
@Model.Exception
+
+} \ No newline at end of file diff --git a/WebServer.Test/Views/localhost/fonts/OpenSans/Light.eot b/WebServer.Test/Views/localhost/fonts/OpenSans/Light.eot new file mode 100644 index 0000000..4616b01 Binary files /dev/null and b/WebServer.Test/Views/localhost/fonts/OpenSans/Light.eot differ diff --git a/WebServer.Test/Views/localhost/fonts/OpenSans/Light.ttf b/WebServer.Test/Views/localhost/fonts/OpenSans/Light.ttf new file mode 100644 index 0000000..0d38189 Binary files /dev/null and b/WebServer.Test/Views/localhost/fonts/OpenSans/Light.ttf differ diff --git a/WebServer.Test/Views/localhost/fonts/OpenSans/Light.woff b/WebServer.Test/Views/localhost/fonts/OpenSans/Light.woff new file mode 100644 index 0000000..ec5db17 Binary files /dev/null and b/WebServer.Test/Views/localhost/fonts/OpenSans/Light.woff differ diff --git a/WebServer.Test/Views/localhost/images/Chalkboard.webp b/WebServer.Test/Views/localhost/images/Chalkboard.webp new file mode 100644 index 0000000..6d48d30 Binary files /dev/null and b/WebServer.Test/Views/localhost/images/Chalkboard.webp differ diff --git a/WebServer.Test/Views/localhost/styles/common.css b/WebServer.Test/Views/localhost/styles/common.css new file mode 100644 index 0000000..c7eb314 --- /dev/null +++ b/WebServer.Test/Views/localhost/styles/common.css @@ -0,0 +1,50 @@ +@charset "UTF-8"; + +@font-face { + font-family: 'Open Sans Light'; + src: url('/fonts/OpenSans/Light.eot'); + src: local('Open Sans Light'), + url('/fonts/OpenSans/Light.woff') format('woff'), + url('/fonts/OpenSans/Light.ttf') format('truetype'); +} + +html, body { + min-height: 100vh; + width: 100%; + margin: 0; + padding: 0; + font-family: "Open Sans Light", sans-serif; + color: #fff; + background-color: #131a26; +} + +body { + padding: 0; + margin: 0; + position: relative; + min-height: 100vh; + background-image: url('/images/Chalkboard.webp'); + background-size: cover; + background-position: center center; + z-index: -1; +} + +body::before { + content: ""; + pointer-events: none; + height: 100vh; + width: 100vw; + background-color: rgba(0, 0, 0, 0.5); + position: absolute; + top: 0; + left: 0; + z-index: inherit; +} + +.centerize { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + text-align: center; +} \ No newline at end of file diff --git a/WebServer.Test/Views/localhost/test123/_Layout.cshtml b/WebServer.Test/Views/localhost/test123/_Layout.cshtml new file mode 100644 index 0000000..1e53d53 --- /dev/null +++ b/WebServer.Test/Views/localhost/test123/_Layout.cshtml @@ -0,0 +1,10 @@ + + + + + Layout2 + + + @RenderBody(); + + \ No newline at end of file diff --git a/WebServer.Test/Views/localhost/test123/index.cshtml b/WebServer.Test/Views/localhost/test123/index.cshtml index 9c6c484..ed2ee05 100644 --- a/WebServer.Test/Views/localhost/test123/index.cshtml +++ b/WebServer.Test/Views/localhost/test123/index.cshtml @@ -1,7 +1,7 @@ @using RazorLight @inherits TemplatePage @{ - Layout = "/_Layout.cshtml"; + Layout = "/test123/_Layout.cshtml"; ViewBag.Title = "Hello World!"; } diff --git a/WebServer/Extensions/ExpandoObject.cs b/WebServer/Extensions/ExpandoObject.cs new file mode 100644 index 0000000..171cd43 --- /dev/null +++ b/WebServer/Extensions/ExpandoObject.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Text; + +namespace WebServer.Extensions { + public static class ExpandoObjectExt { + public static object GetPropertyOrDefault(this ExpandoObject expando, string propertyName, object defaultValue) { + if (expando is IDictionary dict) { + if (!dict.TryGetValue(propertyName, out var result)) + dict.Add(propertyName, result = defaultValue); + return result; + } + return defaultValue; + } + + public static bool TryGetProperty(this ExpandoObject expando, string propertyName, out object value) { + value = null; + return expando is IDictionary dict + && dict.TryGetValue(propertyName, out value); + } + + } +}