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
# Visual Studio 14
VisualStudioVersion = 14.0.22530.0
VisualStudioVersion = 14.0.22823.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{509A6F36-AD80-4A18-B5B1-717D38DFF29D}"
EndProject

View File

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

View File

@ -17,54 +17,11 @@ namespace Microsoft.AspNet.Diagnostics
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>
/// 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.
/// </summary>
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 26 "CompilationErrorPage.cshtml"
if (!Model.Options.ShowExceptionDetails)
foreach (var errorDetail in Model.ErrorDetails)
{
#line default
#line hidden
WriteLiteral(" <h2>");
#line 28 "CompilationErrorPage.cshtml"
Write(Resources.ErrorPageHtml_EnableShowExceptions);
#line default
#line hidden
WriteLiteral("</h2>\r\n");
WriteLiteral(" <div id=\"stackpage\" class=\"page\">\r\n");
#line 29 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" ");
#line 30 "CompilationErrorPage.cshtml"
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 29 "CompilationErrorPage.cshtml"
int tabIndex = 6;
#line default
#line hidden
WriteLiteral("\r\n");
#line 36 "CompilationErrorPage.cshtml"
#line 30 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 36 "CompilationErrorPage.cshtml"
var fileName = errorDetail.StackFrames.FirstOrDefault()?.File;
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 30 "CompilationErrorPage.cshtml"
var fileName = errorDetail.StackFrames.FirstOrDefault()?.File;
if (!string.IsNullOrEmpty(fileName))
{
#line default
#line hidden
WriteLiteral(" <li class=\"frame\"");
WriteAttribute("tabindex", Tuple.Create(" tabindex=\"", 1496), Tuple.Create("\"", 1516),
Tuple.Create(Tuple.Create("", 1507), Tuple.Create<System.Object, System.Int32>(tabIndex, 1507), false));
WriteLiteral(">\r\n");
#line 48 "CompilationErrorPage.cshtml"
WriteLiteral(" <div class=\"titleerror\">");
#line 34 "CompilationErrorPage.cshtml"
Write(fileName);
#line default
#line hidden
WriteLiteral("</div>\r\n");
#line 35 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
#line 48 "CompilationErrorPage.cshtml"
tabIndex++;
WriteLiteral("\r\n <br />\r\n <ul>\r\n");
#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 hidden
WriteLiteral("\r\n");
#line 49 "CompilationErrorPage.cshtml"
#line 43 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 49 "CompilationErrorPage.cshtml"
if (!string.IsNullOrEmpty(frame.ErrorDetails))
{
#line 43 "CompilationErrorPage.cshtml"
if (!string.IsNullOrEmpty(frame.ErrorDetails))
{
#line default
#line hidden
WriteLiteral(" <h3>");
#line 51 "CompilationErrorPage.cshtml"
Write(frame.ErrorDetails);
WriteLiteral(" <h3>");
#line 45 "CompilationErrorPage.cshtml"
Write(frame.ErrorDetails);
#line default
#line hidden
WriteLiteral("</h3>\r\n");
#line 52 "CompilationErrorPage.cshtml"
}
#line 46 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral("\r\n");
#line 54 "CompilationErrorPage.cshtml"
#line 48 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 54 "CompilationErrorPage.cshtml"
if (frame.Line != 0 && frame.ContextCode.Any())
{
#line 48 "CompilationErrorPage.cshtml"
if (frame.Line != 0 && frame.ContextCode.Any())
{
#line default
#line hidden
WriteLiteral(" <div class=\"source\">\r\n");
#line 57 "CompilationErrorPage.cshtml"
WriteLiteral(" <div class=\"source\">\r\n");
#line 51 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 57 "CompilationErrorPage.cshtml"
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 51 "CompilationErrorPage.cshtml"
if (frame.PreContextCode != null)
{
#line default
#line hidden
WriteLiteral(" <ol");
WriteAttribute("start", Tuple.Create(" start=\"", 2524), Tuple.Create("\"", 2543),
Tuple.Create(Tuple.Create("", 2532), Tuple.Create<System.Object, System.Int32>(frame.Line, 2532), false));
WriteLiteral(" class=\"highlight\">\r\n");
#line 67 "CompilationErrorPage.cshtml"
WriteAttribute("start", Tuple.Create(" start=\"", 1777), Tuple.Create("\"", 1806),
Tuple.Create(Tuple.Create("", 1785), Tuple.Create<System.Object, System.Int32>(frame.PreContextLine, 1785), false));
WriteLiteral(" class=\"collapsible\">\r\n");
#line 54 "CompilationErrorPage.cshtml"
#line default
#line hidden
#line 67 "CompilationErrorPage.cshtml"
foreach (var line in frame.ContextCode)
#line 54 "CompilationErrorPage.cshtml"
foreach (var line in frame.PreContextCode)
{
#line default
#line hidden
WriteLiteral(" <li><span>");
#line 69 "CompilationErrorPage.cshtml"
#line 56 "CompilationErrorPage.cshtml"
Write(line);
#line default
#line hidden
WriteLiteral("</span></li>\r\n");
#line 70 "CompilationErrorPage.cshtml"
#line 57 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
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 hidden
#line 72 "CompilationErrorPage.cshtml"
if (frame.PostContextCode != null)
#line 61 "CompilationErrorPage.cshtml"
foreach (var line in frame.ContextCode)
{
#line default
#line hidden
WriteLiteral(" <ol");
WriteAttribute("start", Tuple.Create(" start=\'", 3004), Tuple.Create("\'", 3029),
Tuple.Create(Tuple.Create("", 3012), Tuple.Create<System.Object, System.Int32>(frame.Line + 1, 3012), false));
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);
WriteLiteral(" <li><span>");
#line 63 "CompilationErrorPage.cshtml"
Write(line);
#line default
#line hidden
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 default
#line hidden
WriteLiteral(" </ol>\r\n");
#line 80 "CompilationErrorPage.cshtml"
}
#line default
#line hidden
WriteLiteral(" </div>\r\n");
WriteLiteral(" </ul>\r\n <br />\r\n </div>\r\n");
#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

View File

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

File diff suppressed because one or more lines are too long

View File

@ -30,232 +30,200 @@
</head>
<body>
<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>
@{
StackFrame 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))
<div class="titleerror">@errorDetail.Error.GetType().Name: @{ Output.Write(HtmlEncodeAndReplaceLineBreaks(errorDetail.Error.Message)); }</div>
@{
StackFrame firstFrame = null;
firstFrame = errorDetail.StackFrames.FirstOrDefault();
if (firstFrame != null)
{
<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))
location = firstFrame.Function;
}/* TODO: TargetSite is not defined
else if (errorDetail.Error.TargetSite != null && errorDetail.Error.TargetSite.DeclaringType != null)
{
<p class="location">@location</p>
}
else
{
<p class="location">@Resources.ErrorPageHtml_UnknownLocation</p>
}
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>
}
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">
@if (Model.Options.ShowExceptionDetails)
{
<li id="stack" tabindex="1" class="selected">
@Resources.ErrorPageHtml_StackButton
</li>
}
@if (Model.Options.ShowQuery)
{
<li id="query" tabindex="2">
@Resources.ErrorPageHtml_QueryButton
</li>
}
@if (Model.Options.ShowCookies)
{
<li id="cookies" tabindex="3">
@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>
}
<li id="stack" tabindex="1" class="selected">
@Resources.ErrorPageHtml_StackButton
</li>
<li id="query" tabindex="2">
@Resources.ErrorPageHtml_QueryButton
</li>
<li id="cookies" tabindex="3">
@Resources.ErrorPageHtml_CookiesButton
</li>
<li id="headers" tabindex="4">
@Resources.ErrorPageHtml_HeadersButton
</li>
<li id="environment" tabindex="5">
@Resources.ErrorPageHtml_EnvironmentButton
</li>
</ul>
@if (Model.Options.ShowExceptionDetails)
{
<div id="stackpage" class="page">
<ul>
@{ int tabIndex = 6; }
@foreach (var errorDetail in Model.ErrorDetails)
{
<li>
<h2 class="stackerror">@errorDetail.Error.GetType().Name: @errorDetail.Error.Message</h2>
<ul>
@foreach (var frame in errorDetail.StackFrames)
{
<li class="frame" tabindex="@tabIndex">
@{ tabIndex++; }
@if (string.IsNullOrEmpty(frame.File))
{
<h3>@frame.Function</h3>
}
else
{
<h3>@frame.Function in <code title="@frame.File">@System.IO.Path.GetFileName(frame.File)</code></h3>
}
<div id="stackpage" class="page">
<ul>
@{ int tabIndex = 6; }
@foreach (var errorDetail in Model.ErrorDetails)
{
<li>
<h2 class="stackerror">@errorDetail.Error.GetType().Name: @errorDetail.Error.Message</h2>
<ul>
@foreach (var frame in errorDetail.StackFrames)
{
<li class="frame" tabindex="@tabIndex">
@{ tabIndex++; }
@if (string.IsNullOrEmpty(frame.File))
{
<h3>@frame.Function</h3>
}
else
{
<h3>@frame.Function in <code title="@frame.File">@System.IO.Path.GetFileName(frame.File)</code></h3>
}
@if (frame.Line != 0 && frame.ContextCode.Any())
{
<div class="source">
@if (frame.PreContextCode != null)
{
<ol start="@frame.PreContextLine" class="collapsible">
@foreach (var line in frame.PreContextCode)
{
<li><span>@line</span></li>
}
</ol>
}
<ol start="@frame.Line" class="highlight">
@foreach (var line in frame.ContextCode)
@if (frame.Line != 0 && frame.ContextCode.Any())
{
<div class="source">
@if (frame.PreContextCode != null)
{
<ol start="@frame.PreContextLine" class="collapsible">
@foreach (var line in frame.PreContextCode)
{
<li><span>@line</span></li>
}
</ol>
}
@if (frame.PostContextCode != null)
<ol start="@frame.Line" class="highlight">
@foreach (var line in frame.ContextCode)
{
<ol start='@(frame.Line + 1)' class="collapsible">
@foreach (var line in frame.PostContextCode)
{
<li><span>@line</span></li>
}
</ol>
}
</div>
}
</li>
}
</ul>
</li>
}
</ul>
</div>
}
@if (Model.Options.ShowQuery)
{
<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>
<li><span>@line</span></li>
}
</ol>
@if (frame.PostContextCode != null)
{
<ol start='@(frame.Line + 1)' class="collapsible">
@foreach (var line in frame.PostContextCode)
{
<li><span>@line</span></li>
}
</ol>
}
</div>
}
</li>
}
</ul>
</li>
}
else
{
<p>@Resources.ErrorPageHtml_NoQueryStringData</p>
}
</div>
}
@if (Model.Options.ShowCookies)
{
/* TODO:
<div id="cookiespage" class="page">
@if (Model.Cookies.Any())
{
<table>
<thead>
<tr>
<th>@Resources.ErrorPageHtml_VariableColumn</th>
<th>@Resources.ErrorPageHtml_ValueColumn</th>
</tr>
</thead>
<tbody>
@foreach (var kv in Model.Cookies.OrderBy(kv => kv.Key))
</ul>
</div>
<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>@kv.Value</td>
<td>@v</td>
</tr>
}
</tbody>
</table>
}
else
{
<p>@Resources.ErrorPageHtml_NoCookieData</p>
}
</div>
*/
}
@if (Model.Options.ShowHeaders)
{
<div id="headerspage" class="page">
@if (Model.Headers.Any())
{
<table>
<thead>
}
</tbody>
</table>
}
else
{
<p>@Resources.ErrorPageHtml_NoQueryStringData</p>
}
</div>
<div id="cookiespage" class="page">
@if (Model.Cookies.Any())
{
<table>
<thead>
<tr>
<th>@Resources.ErrorPageHtml_VariableColumn</th>
<th>@Resources.ErrorPageHtml_ValueColumn</th>
</tr>
</thead>
<tbody>
@foreach (var kv in Model.Cookies.OrderBy(kv => kv.Key))
{
<tr>
<th>@Resources.ErrorPageHtml_VariableColumn</th>
<th>@Resources.ErrorPageHtml_ValueColumn</th>
<td>@kv.Key</td>
<td>@kv.Value</td>
</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>
}
</tbody>
</table>
}
else
{
<p>@Resources.ErrorPageHtml_NoCookieData</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:
<div id="environmentpage" class="page">
<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.
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Http;
@ -19,28 +18,28 @@ namespace Microsoft.AspNet.Diagnostics.Views
public ErrorPageOptions Options { get; set; }
/// <summary>
/// Detailed information about each exception in the stack
/// Detailed information about each exception in the stack.
/// </summary>
public IEnumerable<ErrorDetails> ErrorDetails { get; set; }
/// <summary>
/// Parsed query data
/// Parsed query data.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public IReadableStringCollection Query { get; set; }
/* TODO:
/// <summary>
/// Request cookies
/// Request cookies.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public RequestCookieCollection Cookies { get; set; }
*/
public IReadableStringCollection Cookies { get; set; }
/// <summary>
/// Request headers
/// Request headers.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public IDictionary<string, string[]> Headers { get; set; }
/* TODO:
/// <summary>
/// The request environment

View File

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