From 3f6b558cf34aa2f57d0e8e6749f4a2c1a4c68743 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 25 Aug 2016 17:21:29 -0700 Subject: [PATCH] Revert "Remove existing implementation of StartupExceptionPage and use the one in Common" This reverts commit 83e0d4798eb4fd9113d06c54bba9d69faefa3d96. --- .../Internal/WebHost.cs | 43 +- .../Properties/Resources.Designer.cs | 78 -- .../Resources.resx | 129 -- .../ExceptionPage/Views/ErrorPage.Designer.cs | 1055 ----------------- .../ExceptionPage/Views/ErrorPage.cshtml | 162 --- .../Startup/ExceptionPage/Views/ErrorPage.css | 195 --- .../Startup/ExceptionPage/Views/ErrorPage.js | 192 --- .../ExceptionPage/Views/ErrorPageModel.cs | 29 - .../Startup/StartupExceptionPage.cs | 329 +++++ src/Microsoft.AspNetCore.Hosting/project.json | 11 +- .../WebHostBuilderTests.cs | 8 +- 11 files changed, 340 insertions(+), 1891 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Hosting/Properties/Resources.Designer.cs delete mode 100644 src/Microsoft.AspNetCore.Hosting/Resources.resx delete mode 100644 src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPage.Designer.cs delete mode 100644 src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPage.cshtml delete mode 100644 src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPage.css delete mode 100644 src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPage.js delete mode 100644 src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPageModel.cs create mode 100644 src/Microsoft.AspNetCore.Hosting/Startup/StartupExceptionPage.cs diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs index 8098c5838f..c2a591b5b8 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs @@ -5,20 +5,16 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; using System.Threading; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Builder; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; -using Microsoft.AspNetCore.Hosting.Views; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.StackTrace.Sources; namespace Microsoft.AspNetCore.Hosting.Internal { @@ -172,44 +168,15 @@ namespace Microsoft.AspNetCore.Hosting.Internal // Generate an HTML error page. var hostingEnv = _applicationServices.GetRequiredService(); var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors; + var errorBytes = StartupExceptionPage.GenerateErrorHtml(showDetailedErrors, ex); - var model = new ErrorPageModel(); - var runtimeType = Microsoft.Extensions.Internal.RuntimeEnvironment.RuntimeType; - model.RuntimeDisplayName = (runtimeType == "CoreCLR") ? ".NET Core" : runtimeType == "CLR" ? ".NET Framework" : "Mono"; -#if NETSTANDARD1_3 - var systemRuntimeAssembly = typeof(System.ComponentModel.DefaultValueAttribute).GetTypeInfo().Assembly; - var assemblyVersion = new AssemblyName(systemRuntimeAssembly.FullName).Version.ToString(); - var clrVersion = assemblyVersion; -#else - var clrVersion = Environment.Version.ToString(); -#endif - model.RuntimeArchitecture = RuntimeInformation.ProcessArchitecture.ToString(); - var currentAssembly = typeof(ErrorPage).GetTypeInfo().Assembly; - model.CurrentAssemblyVesion = currentAssembly - .GetCustomAttribute() - .InformationalVersion; - model.ClrVersion = clrVersion; - model.OperatingSystemDescription = RuntimeInformation.OSDescription; - - if (showDetailedErrors) - { - var exceptionDetailProvider = new ExceptionDetailsProvider( - hostingEnv.ContentRootFileProvider, - sourceCodeLineCount: 6); - - model.ErrorDetails = exceptionDetailProvider.GetDetails(ex); - } - else - { - model.ErrorDetails = new ExceptionDetails[0]; - } - - var errorPage = new ErrorPage(model); return context => { context.Response.StatusCode = 500; - context.Response.Headers["Cache-Control"] = "no-cache"; - return errorPage.ExecuteAsync(context); + context.Response.Headers["Cache-Control"] = "private, max-age=0"; + context.Response.ContentType = "text/html; charset=utf-8"; + context.Response.ContentLength = errorBytes.Length; + return context.Response.Body.WriteAsync(errorBytes, 0, errorBytes.Length); }; } } diff --git a/src/Microsoft.AspNetCore.Hosting/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Hosting/Properties/Resources.Designer.cs deleted file mode 100644 index 397c84eba2..0000000000 --- a/src/Microsoft.AspNetCore.Hosting/Properties/Resources.Designer.cs +++ /dev/null @@ -1,78 +0,0 @@ -// -namespace Microsoft.AspNetCore.Hosting -{ - using System.Globalization; - using System.Reflection; - using System.Resources; - - internal static class Resources - { - private static readonly ResourceManager _resourceManager - = new ResourceManager("Microsoft.AspNetCore.Hosting.Resources", typeof(Resources).GetTypeInfo().Assembly); - - /// - /// Internal Server Error - /// - internal static string ErrorPageHtml_Title - { - get { return GetString("ErrorPageHtml_Title"); } - } - - /// - /// Internal Server Error - /// - internal static string FormatErrorPageHtml_Title() - { - return GetString("ErrorPageHtml_Title"); - } - - /// - /// An error occurred while starting the application. - /// - internal static string ErrorPageHtml_UnhandledException - { - get { return GetString("ErrorPageHtml_UnhandledException"); } - } - - /// - /// An error occurred while starting the application. - /// - internal static string FormatErrorPageHtml_UnhandledException() - { - return GetString("ErrorPageHtml_UnhandledException"); - } - - /// - /// Unknown location - /// - internal static string ErrorPageHtml_UnknownLocation - { - get { return GetString("ErrorPageHtml_UnknownLocation"); } - } - - /// - /// Unknown location - /// - internal static string FormatErrorPageHtml_UnknownLocation() - { - return GetString("ErrorPageHtml_UnknownLocation"); - } - - private static string GetString(string name, params string[] formatterNames) - { - var value = _resourceManager.GetString(name); - - System.Diagnostics.Debug.Assert(value != null); - - if (formatterNames != null) - { - for (var i = 0; i < formatterNames.Length; i++) - { - value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); - } - } - - return value; - } - } -} diff --git a/src/Microsoft.AspNetCore.Hosting/Resources.resx b/src/Microsoft.AspNetCore.Hosting/Resources.resx deleted file mode 100644 index 6af9630466..0000000000 --- a/src/Microsoft.AspNetCore.Hosting/Resources.resx +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Internal Server Error - - - An error occurred while starting the application. - - - Unknown location - - \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPage.Designer.cs b/src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPage.Designer.cs deleted file mode 100644 index 52a6db45d3..0000000000 --- a/src/Microsoft.AspNetCore.Hosting/Startup/ExceptionPage/Views/ErrorPage.Designer.cs +++ /dev/null @@ -1,1055 +0,0 @@ -namespace Microsoft.AspNetCore.Hosting.Views -{ -#line 1 "ErrorPage.cshtml" -using System - -#line default -#line hidden - ; -#line 2 "ErrorPage.cshtml" -using System.Globalization - -#line default -#line hidden - ; -#line 3 "ErrorPage.cshtml" -using System.Linq - -#line default -#line hidden - ; -#line 4 "ErrorPage.cshtml" -using System.Net - -#line default -#line hidden - ; -#line 5 "ErrorPage.cshtml" -using System.Reflection - -#line default -#line hidden - ; -#line 6 "ErrorPage.cshtml" -using Microsoft.AspNetCore.Hosting.Views - -#line default -#line hidden - ; - using System.Threading.Tasks; - - internal class ErrorPage : Microsoft.Extensions.RazorViews.BaseView - { -#line 9 "ErrorPage.cshtml" - - public ErrorPage(ErrorPageModel model) - { - Model = model; - } - - public ErrorPageModel Model { get; set; } - -#line default -#line hidden - #line hidden - public ErrorPage() - { - } - - #pragma warning disable 1998 - public override async Task ExecuteAsync() - { - WriteLiteral("\r\n"); -#line 17 "ErrorPage.cshtml" - - Response.ContentType = "text/html; charset=utf-8"; - var location = string.Empty; - -#line default -#line hidden - - WriteLiteral("\r\n