Remove ErrorPageOptions properties except SourceCodeLineCount

- Removed all properties except `SourceCodeLineCount`
- Updated ErroPageMiddleware (including some minor code-style changes)
- Updated CompilationErrorPage.cshtml and ErrorPage.cshtml
- Added `run` command to PageGenerator project.json to execute from command line
- Include cookies on error page
- Removed showSource parameter
- Remove unused exception parameter
This commit is contained in:
Henk Mollema 2015-06-11 14:44:58 +02:00 committed by Chris R
parent ccdedc704d
commit 0da9e2bec5
10 changed files with 953 additions and 1173 deletions

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 14
VisualStudioVersion = 14.0.22530.0 VisualStudioVersion = 14.0.22823.1
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{509A6F36-AD80-4A18-B5B1-717D38DFF29D}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{509A6F36-AD80-4A18-B5B1-717D38DFF29D}"
EndProject EndProject

View File

@ -16,7 +16,7 @@ namespace StatusCodePagesSample
{ {
public void Configure(IApplicationBuilder app) public void Configure(IApplicationBuilder app)
{ {
app.UseErrorPage(ErrorPageOptions.ShowAll); app.UseErrorPage();
app.UseStatusCodePages(); // There is a default response but any of the following can be used to change the behavior. app.UseStatusCodePages(); // There is a default response but any of the following can be used to change the behavior.
// app.UseStatusCodePages(context => context.HttpContext.Response.SendAsync("Handler, status code: " + context.HttpContext.Response.StatusCode, "text/plain")); // app.UseStatusCodePages(context => context.HttpContext.Response.SendAsync("Handler, status code: " + context.HttpContext.Response.StatusCode, "text/plain"));

View File

@ -12,8 +12,8 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Views; using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.Runtime;
namespace Microsoft.AspNet.Diagnostics namespace Microsoft.AspNet.Diagnostics
{ {
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Diagnostics
{ {
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
private readonly ErrorPageOptions _options; private readonly ErrorPageOptions _options;
private static bool IsMono = Type.GetType("Mono.Runtime") != null; private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class /// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
@ -70,17 +70,16 @@ namespace Microsoft.AspNet.Diagnostics
var compilationException = ex as ICompilationException; var compilationException = ex as ICompilationException;
if (compilationException != null) if (compilationException != null)
{ {
return DisplayCompilationException(context, ex, compilationException); return DisplayCompilationException(context, compilationException);
} }
return DisplayRuntimeException(context, ex); return DisplayRuntimeException(context, ex);
} }
private Task DisplayCompilationException(HttpContext context, private Task DisplayCompilationException(HttpContext context,
Exception ex,
ICompilationException compilationException) ICompilationException compilationException)
{ {
var model = new CompilationErrorPageModel() var model = new CompilationErrorPageModel
{ {
Options = _options, Options = _options,
}; };
@ -93,7 +92,7 @@ namespace Microsoft.AspNet.Diagnostics
StackFrames = stackFrames StackFrames = stackFrames
}; };
var fileContent = compilationFailure.SourceFileContent var fileContent = compilationFailure.SourceFileContent
.Split(new[] { Environment.NewLine }, StringSplitOptions.None); .Split(new[] { Environment.NewLine }, StringSplitOptions.None);
foreach (var item in compilationFailure.Messages) foreach (var item in compilationFailure.Messages)
{ {
@ -104,11 +103,8 @@ namespace Microsoft.AspNet.Diagnostics
Function = string.Empty Function = string.Empty
}; };
if (_options.ShowSourceCode) ReadFrameContent(frame, fileContent, item.StartLine, item.EndLine);
{ frame.ErrorDetails = item.Message;
ReadFrameContent(frame, fileContent, item.StartLine, item.EndLine);
frame.ErrorDetails = item.Message;
}
stackFrames.Add(frame); stackFrames.Add(frame);
} }
@ -128,62 +124,49 @@ namespace Microsoft.AspNet.Diagnostics
{ {
var request = context.Request; var request = context.Request;
ErrorPageModel model = new ErrorPageModel() var model = new ErrorPageModel
{ {
Options = _options, Options = _options,
ErrorDetails = GetErrorDetails(ex).Reverse(),
Query = request.Query,
Cookies = request.Cookies,
Headers = request.Headers
}; };
if (_options.ShowExceptionDetails) /* TODO:
{
model.ErrorDetails = GetErrorDetails(ex, _options.ShowSourceCode).Reverse();
}
if (_options.ShowQuery)
{
model.Query = request.Query;
}/* TODO:
if (_options.ShowCookies)
{
model.Cookies = request.Cookies;
}*/
if (_options.ShowHeaders)
{
model.Headers = request.Headers;
}/* TODO:
if (_options.ShowEnvironment)
{
model.Environment = context; model.Environment = context;
}*/ */
var errorPage = new ErrorPage(model); var errorPage = new ErrorPage(model);
return errorPage.ExecuteAsync(context); return errorPage.ExecuteAsync(context);
} }
private IEnumerable<ErrorDetails> GetErrorDetails(Exception ex, bool showSource) private IEnumerable<ErrorDetails> GetErrorDetails(Exception ex)
{ {
for (Exception scan = ex; scan != null; scan = scan.InnerException) for (var scan = ex; scan != null; scan = scan.InnerException)
{ {
yield return new ErrorDetails yield return new ErrorDetails
{ {
Error = scan, Error = scan,
StackFrames = StackFrames(scan, showSource) StackFrames = StackFrames(scan)
}; };
} }
} }
private IEnumerable<StackFrame> StackFrames(Exception ex, bool showSource) private IEnumerable<StackFrame> StackFrames(Exception ex)
{ {
var stackTrace = ex.StackTrace; var stackTrace = ex.StackTrace;
if (!string.IsNullOrEmpty(stackTrace)) if (!string.IsNullOrEmpty(stackTrace))
{ {
var heap = new Chunk { Text = stackTrace + Environment.NewLine, End = stackTrace.Length + Environment.NewLine.Length }; var heap = new Chunk { Text = stackTrace + Environment.NewLine, End = stackTrace.Length + Environment.NewLine.Length };
for (Chunk line = heap.Advance(Environment.NewLine); line.HasValue; line = heap.Advance(Environment.NewLine)) for (var line = heap.Advance(Environment.NewLine); line.HasValue; line = heap.Advance(Environment.NewLine))
{ {
yield return StackFrame(line, showSource); yield return StackFrame(line);
} }
} }
} }
private StackFrame StackFrame(Chunk line, bool showSource) private StackFrame StackFrame(Chunk line)
{ {
line.Advance(" at "); line.Advance(" at ");
string function = line.Advance(" in ").ToString(); string function = line.Advance(" in ").ToString();
@ -198,16 +181,16 @@ namespace Microsoft.AspNet.Diagnostics
int lineNumber = line.ToInt32(); int lineNumber = line.ToInt32();
return string.IsNullOrEmpty(file) return string.IsNullOrEmpty(file)
? LoadFrame(string.IsNullOrEmpty(function) ? line.ToString() : function, string.Empty, 0, showSource) ? LoadFrame(string.IsNullOrEmpty(function) ? line.ToString() : function, string.Empty, 0)
: LoadFrame(function, file, lineNumber, showSource); : LoadFrame(function, file, lineNumber);
} }
private StackFrame LoadFrame(string function, string file, int lineNumber, bool showSource) private StackFrame LoadFrame(string function, string file, int lineNumber)
{ {
var frame = new StackFrame { Function = function, File = file, Line = lineNumber }; var frame = new StackFrame { Function = function, File = file, Line = lineNumber };
if (showSource && File.Exists(file)) if (File.Exists(file))
{ {
IEnumerable<string> code = File.ReadLines(file); var code = File.ReadLines(file);
ReadFrameContent(frame, code, lineNumber, lineNumber); ReadFrameContent(frame, code, lineNumber, lineNumber);
} }
return frame; return frame;
@ -230,10 +213,7 @@ namespace Microsoft.AspNet.Diagnostics
public int Start { get; set; } public int Start { get; set; }
public int End { get; set; } public int End { get; set; }
public bool HasValue public bool HasValue => Text != null;
{
get { return Text != null; }
}
public Chunk Advance(string delimiter) public Chunk Advance(string delimiter)
{ {
@ -256,7 +236,7 @@ namespace Microsoft.AspNet.Diagnostics
public int ToInt32() public int ToInt32()
{ {
int value; int value;
return HasValue && Int32.TryParse( return HasValue && int.TryParse(
Text.Substring(Start, End - Start), Text.Substring(Start, End - Start),
NumberStyles.Integer, NumberStyles.Integer,
CultureInfo.InvariantCulture, CultureInfo.InvariantCulture,

View File

@ -17,54 +17,11 @@ namespace Microsoft.AspNet.Diagnostics
SourceCodeLineCount = 6; SourceCodeLineCount = 6;
} }
/// <summary>
/// Returns a new instance of ErrorPageOptions with all visibility options enabled by default.
/// </summary>
public static ErrorPageOptions ShowAll => new ErrorPageOptions
{
ShowExceptionDetails = true,
ShowSourceCode = true,
ShowQuery = true,
ShowCookies = true,
ShowHeaders = true,
ShowEnvironment = true,
};
/// <summary>
/// Enables the display of exception types, messages, and stack traces.
/// </summary>
public bool ShowExceptionDetails { get; set; }
/// <summary>
/// Enabled the display of local source code around exception stack frames.
/// </summary>
public bool ShowSourceCode { get; set; }
/// <summary> /// <summary>
/// Determines how many lines of code to include before and after the line of code /// Determines how many lines of code to include before and after the line of code
/// present in an exception's stack frame. Only applies when symbols are available and /// present in an exception's stack frame. Only applies when symbols are available and
/// source code referenced by the exception stack trace is present on the server. /// source code referenced by the exception stack trace is present on the server.
/// </summary> /// </summary>
public int SourceCodeLineCount { get; set; } public int SourceCodeLineCount { get; set; }
/// <summary>
/// Enables the enumeration of any parsed query values.
/// </summary>
public bool ShowQuery { get; set; }
/// <summary>
/// Enables the enumeration of any parsed request cookies.
/// </summary>
public bool ShowCookies { get; set; }
/// <summary>
/// Enables the enumeration of the request headers.
/// </summary>
public bool ShowHeaders { get; set; }
/// <summary>
/// Enables the enumeration of the OWIN environment values.
/// </summary>
public bool ShowEnvironment { get; set; }
} }
} }

View File

@ -79,298 +79,274 @@ using Views
#line hidden #line hidden
#line 26 "CompilationErrorPage.cshtml" #line 26 "CompilationErrorPage.cshtml"
if (!Model.Options.ShowExceptionDetails) foreach (var errorDetail in Model.ErrorDetails)
{ {
#line default #line default
#line hidden #line hidden
WriteLiteral(" <h2>"); WriteLiteral(" <div id=\"stackpage\" class=\"page\">\r\n");
#line 28 "CompilationErrorPage.cshtml"
Write(Resources.ErrorPageHtml_EnableShowExceptions);
#line default
#line hidden
WriteLiteral("</h2>\r\n");
#line 29 "CompilationErrorPage.cshtml" #line 29 "CompilationErrorPage.cshtml"
}
#line default #line default
#line hidden #line hidden
WriteLiteral(" "); #line 29 "CompilationErrorPage.cshtml"
#line 30 "CompilationErrorPage.cshtml" int tabIndex = 6;
if (Model.Options.ShowExceptionDetails)
{
foreach (var errorDetail in Model.ErrorDetails)
{
#line default
#line hidden
WriteLiteral(" <div id=\"stackpage\" class=\"page\">\r\n");
#line 35 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 35 "CompilationErrorPage.cshtml"
int tabIndex = 6;
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n"); WriteLiteral("\r\n");
#line 36 "CompilationErrorPage.cshtml" #line 30 "CompilationErrorPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 36 "CompilationErrorPage.cshtml" #line 30 "CompilationErrorPage.cshtml"
var fileName = errorDetail.StackFrames.FirstOrDefault()?.File; var fileName = errorDetail.StackFrames.FirstOrDefault()?.File;
if (!string.IsNullOrEmpty(fileName)) if (!string.IsNullOrEmpty(fileName))
{
#line default
#line hidden
WriteLiteral(" <div class=\"titleerror\">");
#line 40 "CompilationErrorPage.cshtml"
Write(fileName);
#line default
#line hidden
WriteLiteral("</div>\r\n");
#line 41 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral("\r\n <br />\r\n <ul>\r\n");
#line 45 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 45 "CompilationErrorPage.cshtml"
foreach (var frame in errorDetail.StackFrames)
{ {
#line default #line default
#line hidden #line hidden
WriteLiteral(" <li class=\"frame\""); WriteLiteral(" <div class=\"titleerror\">");
WriteAttribute("tabindex", Tuple.Create(" tabindex=\"", 1496), Tuple.Create("\"", 1516), #line 34 "CompilationErrorPage.cshtml"
Tuple.Create(Tuple.Create("", 1507), Tuple.Create<System.Object, System.Int32>(tabIndex, 1507), false)); Write(fileName);
WriteLiteral(">\r\n");
#line 48 "CompilationErrorPage.cshtml" #line default
#line hidden
WriteLiteral("</div>\r\n");
#line 35 "CompilationErrorPage.cshtml"
}
#line default #line default
#line hidden #line hidden
#line 48 "CompilationErrorPage.cshtml" WriteLiteral("\r\n <br />\r\n <ul>\r\n");
tabIndex++; #line 39 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 39 "CompilationErrorPage.cshtml"
foreach (var frame in errorDetail.StackFrames)
{
#line default
#line hidden
WriteLiteral(" <li class=\"frame\"");
WriteAttribute("tabindex", Tuple.Create(" tabindex=\"", 1231), Tuple.Create("\"", 1251),
Tuple.Create(Tuple.Create("", 1242), Tuple.Create<System.Object, System.Int32>(tabIndex, 1242), false));
WriteLiteral(">\r\n");
#line 42 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 42 "CompilationErrorPage.cshtml"
tabIndex++;
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n"); WriteLiteral("\r\n");
#line 49 "CompilationErrorPage.cshtml" #line 43 "CompilationErrorPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 49 "CompilationErrorPage.cshtml" #line 43 "CompilationErrorPage.cshtml"
if (!string.IsNullOrEmpty(frame.ErrorDetails)) if (!string.IsNullOrEmpty(frame.ErrorDetails))
{ {
#line default #line default
#line hidden #line hidden
WriteLiteral(" <h3>"); WriteLiteral(" <h3>");
#line 51 "CompilationErrorPage.cshtml" #line 45 "CompilationErrorPage.cshtml"
Write(frame.ErrorDetails); Write(frame.ErrorDetails);
#line default #line default
#line hidden #line hidden
WriteLiteral("</h3>\r\n"); WriteLiteral("</h3>\r\n");
#line 52 "CompilationErrorPage.cshtml" #line 46 "CompilationErrorPage.cshtml"
} }
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n"); WriteLiteral("\r\n");
#line 54 "CompilationErrorPage.cshtml" #line 48 "CompilationErrorPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 54 "CompilationErrorPage.cshtml" #line 48 "CompilationErrorPage.cshtml"
if (frame.Line != 0 && frame.ContextCode.Any()) if (frame.Line != 0 && frame.ContextCode.Any())
{ {
#line default #line default
#line hidden #line hidden
WriteLiteral(" <div class=\"source\">\r\n"); WriteLiteral(" <div class=\"source\">\r\n");
#line 57 "CompilationErrorPage.cshtml" #line 51 "CompilationErrorPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 57 "CompilationErrorPage.cshtml" #line 51 "CompilationErrorPage.cshtml"
if (frame.PreContextCode != null) if (frame.PreContextCode != null)
{ {
#line default
#line hidden
WriteLiteral(" <ol");
WriteAttribute("start", Tuple.Create(" start=\"", 2086), Tuple.Create("\"", 2115),
Tuple.Create(Tuple.Create("", 2094), Tuple.Create<System.Object, System.Int32>(frame.PreContextLine, 2094), false));
WriteLiteral(" class=\"collapsible\">\r\n");
#line 60 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 60 "CompilationErrorPage.cshtml"
foreach (var line in frame.PreContextCode)
{
#line default
#line hidden
WriteLiteral(" <li><span>");
#line 62 "CompilationErrorPage.cshtml"
Write(line);
#line default
#line hidden
WriteLiteral("</span></li>\r\n");
#line 63 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ol>\r\n");
#line 65 "CompilationErrorPage.cshtml"
}
#line default #line default
#line hidden #line hidden
WriteLiteral(" <ol"); WriteLiteral(" <ol");
WriteAttribute("start", Tuple.Create(" start=\"", 2524), Tuple.Create("\"", 2543), WriteAttribute("start", Tuple.Create(" start=\"", 1777), Tuple.Create("\"", 1806),
Tuple.Create(Tuple.Create("", 2532), Tuple.Create<System.Object, System.Int32>(frame.Line, 2532), false)); Tuple.Create(Tuple.Create("", 1785), Tuple.Create<System.Object, System.Int32>(frame.PreContextLine, 1785), false));
WriteLiteral(" class=\"highlight\">\r\n"); WriteLiteral(" class=\"collapsible\">\r\n");
#line 67 "CompilationErrorPage.cshtml" #line 54 "CompilationErrorPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 67 "CompilationErrorPage.cshtml" #line 54 "CompilationErrorPage.cshtml"
foreach (var line in frame.ContextCode) foreach (var line in frame.PreContextCode)
{ {
#line default #line default
#line hidden #line hidden
WriteLiteral(" <li><span>"); WriteLiteral(" <li><span>");
#line 69 "CompilationErrorPage.cshtml" #line 56 "CompilationErrorPage.cshtml"
Write(line); Write(line);
#line default #line default
#line hidden #line hidden
WriteLiteral("</span></li>\r\n"); WriteLiteral("</span></li>\r\n");
#line 70 "CompilationErrorPage.cshtml" #line 57 "CompilationErrorPage.cshtml"
} }
#line default #line default
#line hidden #line hidden
WriteLiteral(" </ol>\r\n"); WriteLiteral(" </ol>\r\n");
#line 72 "CompilationErrorPage.cshtml" #line 59 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" <ol");
WriteAttribute("start", Tuple.Create(" start=\"", 2187), Tuple.Create("\"", 2206),
Tuple.Create(Tuple.Create("", 2195), Tuple.Create<System.Object, System.Int32>(frame.Line, 2195), false));
WriteLiteral(" class=\"highlight\">\r\n");
#line 61 "CompilationErrorPage.cshtml"
#line default #line default
#line hidden #line hidden
#line 72 "CompilationErrorPage.cshtml" #line 61 "CompilationErrorPage.cshtml"
if (frame.PostContextCode != null) foreach (var line in frame.ContextCode)
{ {
#line default #line default
#line hidden #line hidden
WriteLiteral(" <ol"); WriteLiteral(" <li><span>");
WriteAttribute("start", Tuple.Create(" start=\'", 3004), Tuple.Create("\'", 3029), #line 63 "CompilationErrorPage.cshtml"
Tuple.Create(Tuple.Create("", 3012), Tuple.Create<System.Object, System.Int32>(frame.Line + 1, 3012), false)); Write(line);
WriteLiteral(" class=\"collapsible\">\r\n");
#line 75 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 75 "CompilationErrorPage.cshtml"
foreach (var line in frame.PostContextCode)
{
#line default
#line hidden
WriteLiteral(" <li><span>");
#line 77 "CompilationErrorPage.cshtml"
Write(line);
#line default #line default
#line hidden #line hidden
WriteLiteral("</span></li>\r\n"); WriteLiteral("</span></li>\r\n");
#line 64 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ol>\r\n");
#line 66 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 66 "CompilationErrorPage.cshtml"
if (frame.PostContextCode != null)
{
#line default
#line hidden
WriteLiteral(" <ol");
WriteAttribute("start", Tuple.Create(" start=\'", 2635), Tuple.Create("\'", 2660),
Tuple.Create(Tuple.Create("", 2643), Tuple.Create<System.Object, System.Int32>(frame.Line + 1, 2643), false));
WriteLiteral(" class=\"collapsible\">\r\n");
#line 69 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 69 "CompilationErrorPage.cshtml"
foreach (var line in frame.PostContextCode)
{
#line default
#line hidden
WriteLiteral(" <li><span>");
#line 71 "CompilationErrorPage.cshtml"
Write(line);
#line default
#line hidden
WriteLiteral("</span></li>\r\n");
#line 72 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ol>\r\n");
#line 74 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </div>\r\n");
#line 76 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </li>\r\n");
#line 78 "CompilationErrorPage.cshtml" #line 78 "CompilationErrorPage.cshtml"
} }
#line default #line default
#line hidden #line hidden
WriteLiteral(" </ol>\r\n"); WriteLiteral(" </ul>\r\n <br />\r\n </div>\r\n");
#line 80 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </div>\r\n");
#line 82 "CompilationErrorPage.cshtml" #line 82 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </li>\r\n");
#line 84 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </ul>\r\n <br />\r\n </div>\r\n");
#line 88 "CompilationErrorPage.cshtml"
}
} }
#line default #line default

View File

@ -23,69 +23,62 @@
</head> </head>
<body> <body>
<h1>@Resources.ErrorPageHtml_CompilationException</h1> <h1>@Resources.ErrorPageHtml_CompilationException</h1>
@if (!Model.Options.ShowExceptionDetails) @foreach (var errorDetail in Model.ErrorDetails)
{ {
<h2>@Resources.ErrorPageHtml_EnableShowExceptions</h2> <div id="stackpage" class="page">
} @{ int tabIndex = 6; }
@if (Model.Options.ShowExceptionDetails) @{
{ var fileName = errorDetail.StackFrames.FirstOrDefault()?.File;
foreach (var errorDetail in Model.ErrorDetails) if (!string.IsNullOrEmpty(fileName))
{
<div id="stackpage" class="page">
@{ int tabIndex = 6; }
@{
var fileName = errorDetail.StackFrames.FirstOrDefault()?.File;
if (!string.IsNullOrEmpty(fileName))
{
<div class="titleerror">@fileName</div>
}
}
<br />
<ul>
@foreach (var frame in errorDetail.StackFrames)
{ {
<li class="frame" tabindex="@tabIndex"> <div class="titleerror">@fileName</div>
@{ tabIndex++; } }
@if (!string.IsNullOrEmpty(frame.ErrorDetails)) }
{ <br />
<h3>@frame.ErrorDetails</h3> <ul>
} @foreach (var frame in errorDetail.StackFrames)
{
<li class="frame" tabindex="@tabIndex">
@{ tabIndex++; }
@if (!string.IsNullOrEmpty(frame.ErrorDetails))
{
<h3>@frame.ErrorDetails</h3>
}
@if (frame.Line != 0 && frame.ContextCode.Any()) @if (frame.Line != 0 && frame.ContextCode.Any())
{ {
<div class="source"> <div class="source">
@if (frame.PreContextCode != null) @if (frame.PreContextCode != null)
{ {
<ol start="@frame.PreContextLine" class="collapsible"> <ol start="@frame.PreContextLine" class="collapsible">
@foreach (var line in frame.PreContextCode) @foreach (var line in frame.PreContextCode)
{
<li><span>@line</span></li>
}
</ol>
}
<ol start="@frame.Line" class="highlight">
@foreach (var line in frame.ContextCode)
{ {
<li><span>@line</span></li> <li><span>@line</span></li>
} }
</ol> </ol>
@if (frame.PostContextCode != null) }
<ol start="@frame.Line" class="highlight">
@foreach (var line in frame.ContextCode)
{ {
<ol start='@(frame.Line + 1)' class="collapsible"> <li><span>@line</span></li>
@foreach (var line in frame.PostContextCode) }
{ </ol>
<li><span>@line</span></li> @if (frame.PostContextCode != null)
} {
</ol> <ol start='@(frame.Line + 1)' class="collapsible">
} @foreach (var line in frame.PostContextCode)
</div> {
} <li><span>@line</span></li>
</li> }
} </ol>
</ul> }
<br /> </div>
</div> }
} </li>
}
</ul>
<br />
</div>
} }
<script> <script>
//<!-- //<!--

File diff suppressed because one or more lines are too long

View File

@ -30,232 +30,200 @@
</head> </head>
<body> <body>
<h1>@Resources.ErrorPageHtml_UnhandledException</h1> <h1>@Resources.ErrorPageHtml_UnhandledException</h1>
@if (Model.Options.ShowExceptionDetails) @foreach (var errorDetail in Model.ErrorDetails)
{ {
foreach (var errorDetail in Model.ErrorDetails) <div class="titleerror">@errorDetail.Error.GetType().Name: @{ Output.Write(HtmlEncodeAndReplaceLineBreaks(errorDetail.Error.Message)); }</div>
{ @{
<div class="titleerror">@errorDetail.Error.GetType().Name: @{ Output.Write(HtmlEncodeAndReplaceLineBreaks(errorDetail.Error.Message)); }</div> StackFrame firstFrame = null;
@{ firstFrame = errorDetail.StackFrames.FirstOrDefault();
StackFrame firstFrame = null; if (firstFrame != null)
firstFrame = errorDetail.StackFrames.FirstOrDefault();
if (firstFrame != null)
{
location = firstFrame.Function;
}/* TODO: TargetSite is not defined
else if (errorDetail.Error.TargetSite != null && errorDetail.Error.TargetSite.DeclaringType != null)
{
location = errorDetail.Error.TargetSite.DeclaringType.FullName + "." + errorDetail.Error.TargetSite.Name;
}*/
}
if (!string.IsNullOrEmpty(location) && firstFrame != null && !string.IsNullOrEmpty(firstFrame.File))
{ {
<p class="location">@location in <code title="@firstFrame.File">@System.IO.Path.GetFileName(firstFrame.File)</code>, line @firstFrame.Line</p> location = firstFrame.Function;
} }/* TODO: TargetSite is not defined
else if (!string.IsNullOrEmpty(location)) else if (errorDetail.Error.TargetSite != null && errorDetail.Error.TargetSite.DeclaringType != null)
{ {
<p class="location">@location</p> location = errorDetail.Error.TargetSite.DeclaringType.FullName + "." + errorDetail.Error.TargetSite.Name;
} }*/
else }
{ if (!string.IsNullOrEmpty(location) && firstFrame != null && !string.IsNullOrEmpty(firstFrame.File))
<p class="location">@Resources.ErrorPageHtml_UnknownLocation</p> {
} <p class="location">@location in <code title="@firstFrame.File">@System.IO.Path.GetFileName(firstFrame.File)</code>, line @firstFrame.Line</p>
}
else if (!string.IsNullOrEmpty(location))
{
<p class="location">@location</p>
}
else
{
<p class="location">@Resources.ErrorPageHtml_UnknownLocation</p>
} }
}
else
{
<h2>@Resources.ErrorPageHtml_EnableShowExceptions</h2>
} }
<ul id="header"> <ul id="header">
@if (Model.Options.ShowExceptionDetails) <li id="stack" tabindex="1" class="selected">
{ @Resources.ErrorPageHtml_StackButton
<li id="stack" tabindex="1" class="selected"> </li>
@Resources.ErrorPageHtml_StackButton <li id="query" tabindex="2">
</li> @Resources.ErrorPageHtml_QueryButton
} </li>
@if (Model.Options.ShowQuery) <li id="cookies" tabindex="3">
{ @Resources.ErrorPageHtml_CookiesButton
<li id="query" tabindex="2"> </li>
@Resources.ErrorPageHtml_QueryButton <li id="headers" tabindex="4">
</li> @Resources.ErrorPageHtml_HeadersButton
} </li>
@if (Model.Options.ShowCookies) <li id="environment" tabindex="5">
{ @Resources.ErrorPageHtml_EnvironmentButton
<li id="cookies" tabindex="3"> </li>
@Resources.ErrorPageHtml_CookiesButton
</li>
}
@if (Model.Options.ShowHeaders)
{
<li id="headers" tabindex="4">
@Resources.ErrorPageHtml_HeadersButton
</li>
}
@if (Model.Options.ShowEnvironment)
{
<li id="environment" tabindex="5">
@Resources.ErrorPageHtml_EnvironmentButton
</li>
}
</ul> </ul>
@if (Model.Options.ShowExceptionDetails)
{ <div id="stackpage" class="page">
<div id="stackpage" class="page"> <ul>
<ul> @{ int tabIndex = 6; }
@{ int tabIndex = 6; } @foreach (var errorDetail in Model.ErrorDetails)
@foreach (var errorDetail in Model.ErrorDetails) {
{ <li>
<li> <h2 class="stackerror">@errorDetail.Error.GetType().Name: @errorDetail.Error.Message</h2>
<h2 class="stackerror">@errorDetail.Error.GetType().Name: @errorDetail.Error.Message</h2> <ul>
<ul> @foreach (var frame in errorDetail.StackFrames)
@foreach (var frame in errorDetail.StackFrames) {
{ <li class="frame" tabindex="@tabIndex">
<li class="frame" tabindex="@tabIndex"> @{ tabIndex++; }
@{ tabIndex++; } @if (string.IsNullOrEmpty(frame.File))
@if (string.IsNullOrEmpty(frame.File)) {
{ <h3>@frame.Function</h3>
<h3>@frame.Function</h3> }
} else
else {
{ <h3>@frame.Function in <code title="@frame.File">@System.IO.Path.GetFileName(frame.File)</code></h3>
<h3>@frame.Function in <code title="@frame.File">@System.IO.Path.GetFileName(frame.File)</code></h3> }
}
@if (frame.Line != 0 && frame.ContextCode.Any()) @if (frame.Line != 0 && frame.ContextCode.Any())
{ {
<div class="source"> <div class="source">
@if (frame.PreContextCode != null) @if (frame.PreContextCode != null)
{ {
<ol start="@frame.PreContextLine" class="collapsible"> <ol start="@frame.PreContextLine" class="collapsible">
@foreach (var line in frame.PreContextCode) @foreach (var line in frame.PreContextCode)
{
<li><span>@line</span></li>
}
</ol>
}
<ol start="@frame.Line" class="highlight">
@foreach (var line in frame.ContextCode)
{ {
<li><span>@line</span></li> <li><span>@line</span></li>
} }
</ol> </ol>
}
@if (frame.PostContextCode != null) <ol start="@frame.Line" class="highlight">
@foreach (var line in frame.ContextCode)
{ {
<ol start='@(frame.Line + 1)' class="collapsible"> <li><span>@line</span></li>
@foreach (var line in frame.PostContextCode) }
{ </ol>
<li><span>@line</span></li>
} @if (frame.PostContextCode != null)
</ol> {
} <ol start='@(frame.Line + 1)' class="collapsible">
</div> @foreach (var line in frame.PostContextCode)
} {
</li> <li><span>@line</span></li>
} }
</ul> </ol>
</li> }
} </div>
</ul> }
</div> </li>
} }
@if (Model.Options.ShowQuery) </ul>
{ </li>
<div id="querypage" class="page">
@if (Model.Query.Any())
{
<table>
<thead>
<tr>
<th>@Resources.ErrorPageHtml_VariableColumn</th>
<th>@Resources.ErrorPageHtml_ValueColumn</th>
</tr>
</thead>
<tbody>
@foreach (var kv in Model.Query.OrderBy(kv => kv.Key))
{
foreach (var v in kv.Value)
{
<tr>
<td>@kv.Key</td>
<td>@v</td>
</tr>
}
}
</tbody>
</table>
} }
else </ul>
{ </div>
<p>@Resources.ErrorPageHtml_NoQueryStringData</p>
} <div id="querypage" class="page">
</div> @if (Model.Query.Any())
} {
@if (Model.Options.ShowCookies) <table>
{ <thead>
/* TODO: <tr>
<div id="cookiespage" class="page"> <th>@Resources.ErrorPageHtml_VariableColumn</th>
@if (Model.Cookies.Any()) <th>@Resources.ErrorPageHtml_ValueColumn</th>
{ </tr>
<table> </thead>
<thead> <tbody>
<tr> @foreach (var kv in Model.Query.OrderBy(kv => kv.Key))
<th>@Resources.ErrorPageHtml_VariableColumn</th> {
<th>@Resources.ErrorPageHtml_ValueColumn</th> foreach (var v in kv.Value)
</tr>
</thead>
<tbody>
@foreach (var kv in Model.Cookies.OrderBy(kv => kv.Key))
{ {
<tr> <tr>
<td>@kv.Key</td> <td>@kv.Key</td>
<td>@kv.Value</td> <td>@v</td>
</tr> </tr>
} }
</tbody> }
</table> </tbody>
} </table>
else }
{ else
<p>@Resources.ErrorPageHtml_NoCookieData</p> {
} <p>@Resources.ErrorPageHtml_NoQueryStringData</p>
</div> }
*/ </div>
}
@if (Model.Options.ShowHeaders) <div id="cookiespage" class="page">
{ @if (Model.Cookies.Any())
<div id="headerspage" class="page"> {
@if (Model.Headers.Any()) <table>
{ <thead>
<table> <tr>
<thead> <th>@Resources.ErrorPageHtml_VariableColumn</th>
<th>@Resources.ErrorPageHtml_ValueColumn</th>
</tr>
</thead>
<tbody>
@foreach (var kv in Model.Cookies.OrderBy(kv => kv.Key))
{
<tr> <tr>
<th>@Resources.ErrorPageHtml_VariableColumn</th> <td>@kv.Key</td>
<th>@Resources.ErrorPageHtml_ValueColumn</th> <td>@kv.Value</td>
</tr> </tr>
</thead> }
<tbody> </tbody>
@foreach (var kv in Model.Headers.OrderBy(kv => kv.Key)) </table>
{ }
foreach (var v in kv.Value) else
{ {
<tr> <p>@Resources.ErrorPageHtml_NoCookieData</p>
<td>@kv.Key</td> }
<td>@v</td> </div>
</tr>
}
}
</tbody>
</table>
}
else
{
<p>@Resources.ErrorPageHtml_NoHeaderData</p>
}
</div>
} }
@if (Model.Options.ShowEnvironment) <div id="headerspage" class="page">
{ @if (Model.Headers.Any())
{
<table>
<thead>
<tr>
<th>@Resources.ErrorPageHtml_VariableColumn</th>
<th>@Resources.ErrorPageHtml_ValueColumn</th>
</tr>
</thead>
<tbody>
@foreach (var kv in Model.Headers.OrderBy(kv => kv.Key))
{
foreach (var v in kv.Value)
{
<tr>
<td>@kv.Key</td>
<td>@v</td>
</tr>
}
}
</tbody>
</table>
}
else
{
<p>@Resources.ErrorPageHtml_NoHeaderData</p>
}
</div>
@{
/* TODO: /* TODO:
<div id="environmentpage" class="page"> <div id="environmentpage" class="page">
<table> <table>

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
@ -19,28 +18,28 @@ namespace Microsoft.AspNet.Diagnostics.Views
public ErrorPageOptions Options { get; set; } public ErrorPageOptions Options { get; set; }
/// <summary> /// <summary>
/// Detailed information about each exception in the stack /// Detailed information about each exception in the stack.
/// </summary> /// </summary>
public IEnumerable<ErrorDetails> ErrorDetails { get; set; } public IEnumerable<ErrorDetails> ErrorDetails { get; set; }
/// <summary> /// <summary>
/// Parsed query data /// Parsed query data.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public IReadableStringCollection Query { get; set; } public IReadableStringCollection Query { get; set; }
/* TODO:
/// <summary> /// <summary>
/// Request cookies /// Request cookies.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public RequestCookieCollection Cookies { get; set; } public IReadableStringCollection Cookies { get; set; }
*/
/// <summary> /// <summary>
/// Request headers /// Request headers.
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public IDictionary<string, string[]> Headers { get; set; } public IDictionary<string, string[]> Headers { get; set; }
/* TODO: /* TODO:
/// <summary> /// <summary>
/// The request environment /// The request environment

View File

@ -1,17 +1,21 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"Microsoft.AspNet.Diagnostics.Elm": "1.0.0-*", "Microsoft.AspNet.Diagnostics.Elm": "1.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*", "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"Microsoft.AspNet.Razor": "4.0.0-*" "Microsoft.AspNet.Razor": "4.0.0-*"
}, },
"frameworks": { "frameworks": {
"dnx451": { }, "dnx451": { },
"dnxcore50": { "dnxcore50": {
"dependencies": { "dependencies": {
"System.Console": "4.0.0-beta-*" "System.Console": "4.0.0-beta-*"
} }
}
} }
},
"commands": {
"run" : "PageGenerator"
}
} }