Initial import from Katana.

This commit is contained in:
Chris Ross 2014-03-13 10:57:15 -07:00
commit 7ddfc9cde4
41 changed files with 8855 additions and 0 deletions

50
.gitattributes vendored Normal file
View File

@ -0,0 +1,50 @@
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.jpg binary
*.png binary
*.gif binary
*.cs text=auto diff=csharp
*.vb text=auto
*.resx text=auto
*.c text=auto
*.cpp text=auto
*.cxx text=auto
*.h text=auto
*.hxx text=auto
*.py text=auto
*.rb text=auto
*.java text=auto
*.html text=auto
*.htm text=auto
*.css text=auto
*.scss text=auto
*.sass text=auto
*.less text=auto
*.js text=auto
*.lisp text=auto
*.clj text=auto
*.sql text=auto
*.php text=auto
*.lua text=auto
*.m text=auto
*.asm text=auto
*.erl text=auto
*.fs text=auto
*.fsx text=auto
*.hs text=auto
*.csproj text=auto
*.vbproj text=auto
*.fsproj text=auto
*.dbproj text=auto
*.sln text=auto eol=crlf

24
.gitignore vendored Normal file
View File

@ -0,0 +1,24 @@
[Oo]bj/
[Bb]in/
TestResults/
.nuget/
_ReSharper.*/
packages/
artifacts/
PublishProfiles/
*.user
*.suo
*.cache
*.docstates
_ReSharper.*
nuget.exe
*net45.csproj
*k10.csproj
*.psess
*.vsp
*.pidb
*.userprefs
*DS_Store
*.ncrunchsolution
*.*sdf
*.ipch

64
DiagnosticsPages.sln Normal file
View File

@ -0,0 +1,64 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30203.2
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Diagnostics.net45", "src\Microsoft.AspNet.Diagnostics\Microsoft.AspNet.Diagnostics.net45.csproj", "{092C4ACA-9F4C-4EDB-8B92-8E9FDF49E74A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Diagnostics.k10", "src\Microsoft.AspNet.Diagnostics\Microsoft.AspNet.Diagnostics.k10.csproj", "{CBE6B125-407F-403E-9E95-4D0836DEE706}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{509A6F36-AD80-4A18-B5B1-717D38DFF29D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{ACAA0157-A8C4-4152-93DE-90CCDF304087}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelcomePageSample.net45", "samples\WelcomePageSample\WelcomePageSample.net45.csproj", "{7385EBB2-36DD-4EF7-AF9E-3C4348991C64}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelcomePageSample.k10", "samples\WelcomePageSample\WelcomePageSample.k10.csproj", "{E2B98257-E434-439E-B61F-A3576F18FD34}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ErrorPageSample.k10", "samples\ErrorPageSample\ErrorPageSample.k10.csproj", "{FA5E49FF-4715-4241-9829-6E720AE5AA1D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ErrorPageSample.net45", "samples\ErrorPageSample\ErrorPageSample.net45.csproj", "{1E44DE4A-BAB3-4383-B63F-63D8416AAC60}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{092C4ACA-9F4C-4EDB-8B92-8E9FDF49E74A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{092C4ACA-9F4C-4EDB-8B92-8E9FDF49E74A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{092C4ACA-9F4C-4EDB-8B92-8E9FDF49E74A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{092C4ACA-9F4C-4EDB-8B92-8E9FDF49E74A}.Release|Any CPU.Build.0 = Release|Any CPU
{CBE6B125-407F-403E-9E95-4D0836DEE706}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBE6B125-407F-403E-9E95-4D0836DEE706}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBE6B125-407F-403E-9E95-4D0836DEE706}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBE6B125-407F-403E-9E95-4D0836DEE706}.Release|Any CPU.Build.0 = Release|Any CPU
{7385EBB2-36DD-4EF7-AF9E-3C4348991C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7385EBB2-36DD-4EF7-AF9E-3C4348991C64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7385EBB2-36DD-4EF7-AF9E-3C4348991C64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7385EBB2-36DD-4EF7-AF9E-3C4348991C64}.Release|Any CPU.Build.0 = Release|Any CPU
{E2B98257-E434-439E-B61F-A3576F18FD34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2B98257-E434-439E-B61F-A3576F18FD34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2B98257-E434-439E-B61F-A3576F18FD34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2B98257-E434-439E-B61F-A3576F18FD34}.Release|Any CPU.Build.0 = Release|Any CPU
{FA5E49FF-4715-4241-9829-6E720AE5AA1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA5E49FF-4715-4241-9829-6E720AE5AA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA5E49FF-4715-4241-9829-6E720AE5AA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA5E49FF-4715-4241-9829-6E720AE5AA1D}.Release|Any CPU.Build.0 = Release|Any CPU
{1E44DE4A-BAB3-4383-B63F-63D8416AAC60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E44DE4A-BAB3-4383-B63F-63D8416AAC60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E44DE4A-BAB3-4383-B63F-63D8416AAC60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E44DE4A-BAB3-4383-B63F-63D8416AAC60}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{092C4ACA-9F4C-4EDB-8B92-8E9FDF49E74A} = {509A6F36-AD80-4A18-B5B1-717D38DFF29D}
{CBE6B125-407F-403E-9E95-4D0836DEE706} = {509A6F36-AD80-4A18-B5B1-717D38DFF29D}
{7385EBB2-36DD-4EF7-AF9E-3C4348991C64} = {ACAA0157-A8C4-4152-93DE-90CCDF304087}
{E2B98257-E434-439E-B61F-A3576F18FD34} = {ACAA0157-A8C4-4152-93DE-90CCDF304087}
{FA5E49FF-4715-4241-9829-6E720AE5AA1D} = {ACAA0157-A8C4-4152-93DE-90CCDF304087}
{1E44DE4A-BAB3-4383-B63F-63D8416AAC60} = {ACAA0157-A8C4-4152-93DE-90CCDF304087}
EndGlobalSection
EndGlobal

13
NuGet.Config Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
</packageSources>
<packageSourceCredentials>
<AspNetVNext>
<add key="Username" value="aspnetreadonly" />
<add key="ClearTextPassword" value="4d8a2d9c-7b80-4162-9978-47e918c9658c" />
</AspNetVNext>
</packageSourceCredentials>
</configuration>

23
build.cmd Normal file
View File

@ -0,0 +1,23 @@
@echo off
cd %~dp0
SETLOCAL
SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe
IF EXIST %CACHED_NUGET% goto copynuget
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"
:copynuget
IF EXIST .nuget\nuget.exe goto restore
md .nuget
copy %CACHED_NUGET% .nuget\nuget.exe > nul
:restore
IF EXIST packages\KoreBuild goto run
.nuget\NuGet.exe install KoreBuild -ExcludeVersion -o packages -nocache -pre
.nuget\NuGet.exe install Sake -version 0.2 -o packages -ExcludeVersion
:run
packages\Sake\tools\Sake.exe -I packages\KoreBuild\build -f makefile.shade %*

3
global.json Normal file
View File

@ -0,0 +1,3 @@
{
"sources": ["src"]
}

7
makefile.shade Normal file
View File

@ -0,0 +1,7 @@
var VERSION='0.1'
var FULL_VERSION='0.1'
var AUTHORS='Microsoft'
use-standard-lifecycle
k-standard-goals

View File

@ -0,0 +1,28 @@
using System;
#if NET45
using System.Diagnostics;
using Microsoft.Owin.Hosting;
#endif
namespace ErrorPageSample
{
public class Program
{
const string baseUrl = "http://localhost:9001/";
public static void Main()
{
#if NET45
using (WebApp.Start<Startup>(new StartOptions(baseUrl)))
{
Console.WriteLine("Listening at {0}", baseUrl);
Process.Start(baseUrl);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
#else
Console.WriteLine("Hello World");
#endif
}
}
}

View File

@ -0,0 +1,27 @@
#if NET45
using System;
using Microsoft.AspNet;
using Microsoft.AspNet.Abstractions;
using Owin;
namespace ErrorPageSample
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Temporary bridge from katana to Owin
app.UseBuilder(ConfigurePK);
}
private void ConfigurePK(IBuilder builder)
{
builder.UseErrorPage();
builder.Run(context =>
{
throw new Exception("Demonstration exception");
});
}
}
}
#endif

View File

@ -0,0 +1,39 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Diagnostics": "",
"Microsoft.AspNet.HttpFeature": "0.1-alpha-*",
"Microsoft.AspNet.Abstractions": "0.1-alpha-*"
},
"configurations": {
"net45": {
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0",
"Microsoft.Owin.Hosting": "2.1.0",
"Microsoft.Owin.Host.HttpListener": "2.1.0",
"Microsoft.AspNet.AppBuilderSupport": "0.1-alpha-*"
}
},
"k10": {
"dependencies": {
"System.Console": "4.0.0.0",
"System.Collections": "4.0.0.0",
"System.Diagnostics.Debug": "4.0.10.0",
"System.Diagnostics.Tools": "4.0.0.0",
"System.Globalization": "4.0.10.0",
"System.IO": "4.0.0.0",
"System.IO.FileSystem": "4.0.0.0",
"System.IO.FileSystem.Primitives": "4.0.0.0",
"System.Linq": "4.0.0.0",
"System.Reflection": "4.0.10.0",
"System.Resources.ResourceManager": "4.0.0.0",
"System.Runtime": "4.0.20.0",
"System.Runtime.Extensions": "4.0.10.0",
"System.Runtime.InteropServices": "4.0.10.0",
"System.Text.Encoding": "4.0.10.0",
"System.Threading.Tasks": "4.0.0.0"
}
}
}
}

View File

@ -0,0 +1,28 @@
using System;
#if NET45
using System.Diagnostics;
using Microsoft.Owin.Hosting;
#endif
namespace WelcomePageSample
{
public class Program
{
const string baseUrl = "http://localhost:9001/";
public static void Main()
{
#if NET45
using (WebApp.Start<Startup>(new StartOptions(baseUrl)))
{
Console.WriteLine("Listening at {0}", baseUrl);
Process.Start(baseUrl);
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
#else
Console.WriteLine("Hello World");
#endif
}
}
}

View File

@ -0,0 +1,22 @@
#if NET45
using Microsoft.AspNet;
using Microsoft.AspNet.Abstractions;
using Owin;
namespace WelcomePageSample
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Temporary bridge from katana to Owin
app.UseBuilder(ConfigurePK);
}
private void ConfigurePK(IBuilder builder)
{
builder.UseWelcomePage();
}
}
}
#endif

View File

@ -0,0 +1,39 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Diagnostics": "",
"Microsoft.AspNet.HttpFeature": "0.1-alpha-*",
"Microsoft.AspNet.Abstractions": "0.1-alpha-*"
},
"configurations": {
"net45": {
"dependencies": {
"Owin": "1.0",
"Microsoft.Owin": "2.1.0",
"Microsoft.Owin.Hosting": "2.1.0",
"Microsoft.Owin.Host.HttpListener": "2.1.0",
"Microsoft.AspNet.AppBuilderSupport": "0.1-alpha-*"
}
},
"k10": {
"dependencies": {
"System.Console": "4.0.0.0",
"System.Collections": "4.0.0.0",
"System.Diagnostics.Debug": "4.0.10.0",
"System.Diagnostics.Tools": "4.0.0.0",
"System.Globalization": "4.0.10.0",
"System.IO": "4.0.0.0",
"System.IO.FileSystem": "4.0.0.0",
"System.IO.FileSystem.Primitives": "4.0.0.0",
"System.Linq": "4.0.0.0",
"System.Reflection": "4.0.10.0",
"System.Resources.ResourceManager": "4.0.0.0",
"System.Runtime": "4.0.20.0",
"System.Runtime.Extensions": "4.0.10.0",
"System.Runtime.InteropServices": "4.0.10.0",
"System.Text.Encoding": "4.0.10.0",
"System.Threading.Tasks": "4.0.0.0"
}
}
}
}

View File

@ -0,0 +1,24 @@
// <copyright file="Constants.cs" company="Microsoft Open Technologies, Inc.">
// Copyright 2011-2013 Microsoft Open Technologies, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
namespace Microsoft.AspNet.Diagnostics
{
internal static class Constants
{
internal const string HostAppMode = "host.AppMode";
internal const string DevMode = "development";
}
}

View File

@ -0,0 +1,53 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
#if DEBUG
using System;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Diagnostics;
namespace Microsoft.AspNet
{
/// <summary>
/// IBuilder extensions for the DiagnosticsPageMiddleware.
/// </summary>
public static class DiagnosticsPageExtensions
{
/// <summary>
/// Adds the DiagnosticsPageMiddleware to the pipeline with the given options.
/// </summary>
/// <param name="builder"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IBuilder UseDiagnosticsPage(this IBuilder builder, DiagnosticsPageOptions options)
{
if (builder == null)
{
throw new ArgumentNullException("builder");
}
return builder.Use(next => new DiagnosticsPageMiddleware(next, options).Invoke);
}
/// <summary>
/// Adds the DiagnosticsPageMiddleware to the pipeline with the given path.
/// </summary>
/// <param name="builder"></param>
/// <param name="path"></param>
/// <returns></returns>
public static IBuilder UseDiagnosticsPage(this IBuilder builder, PathString path)
{
return UseDiagnosticsPage(builder, new DiagnosticsPageOptions { Path = path });
}
/// <summary>
/// Adds the DiagnosticsPageMiddleware to the pipeline.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IBuilder UseDiagnosticsPage(this IBuilder builder)
{
return UseDiagnosticsPage(builder, new DiagnosticsPageOptions());
}
}
}
#endif

View File

@ -0,0 +1,48 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
#if DEBUG
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// A human readable page with basic debugging actions.
/// </summary>
public class DiagnosticsPageMiddleware
{
private readonly RequestDelegate _next;
private readonly DiagnosticsPageOptions _options;
/// <summary>
/// Initializes a new instance of the <see cref="DiagnosticsPageMiddleware"/> class
/// </summary>
/// <param name="next"></param>
/// <param name="options"></param>
public DiagnosticsPageMiddleware(RequestDelegate next, DiagnosticsPageOptions options)
{
_next = next;
_options = options;
}
/// <summary>
/// Process an individual request.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public Task Invoke(HttpContext context)
{
if (!_options.Path.HasValue || _options.Path == context.Request.Path)
{
var page = new DiagnosticsPage();
page.Execute(context);
return Task.FromResult(0);
}
return _next(context);
}
}
}
#endif

View File

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
#if DEBUG
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// Options for the DiagnosticsPageMiddleware
/// </summary>
public class DiagnosticsPageOptions
{
/// <summary>
/// Specifies which requests paths will be responded to. Exact matches only. Leave null to handle all requests.
/// </summary>
public PathString Path { get; set; }
}
}
#endif

View File

@ -0,0 +1,50 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Diagnostics;
namespace Microsoft.AspNet
{
/// <summary>
/// IBuilder extension methods for the ErrorPageMiddleware.
/// </summary>
public static class ErrorPageExtensions
{
/// <summary>
/// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
/// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IBuilder.Properties.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IBuilder UseErrorPage(this IBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException("builder");
}
return builder.UseErrorPage(new ErrorPageOptions());
}
/// <summary>
/// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
/// Full error details are only displayed by default if 'host.AppMode' is set to 'development' in the IBuilder.Properties.
/// </summary>
/// <param name="builder"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IBuilder UseErrorPage(this IBuilder builder, ErrorPageOptions options)
{
if (builder == null)
{
throw new ArgumentNullException("builder");
}
/* TODO: Development, Staging, or Production
string appMode = new AppProperties(builder.Properties).Get<string>(Constants.HostAppMode);
bool isDevMode = string.Equals(Constants.DevMode, appMode, StringComparison.Ordinal);*/
bool isDevMode = true;
return builder.Use(next => new ErrorPageMiddleware(next, options, isDevMode).Invoke);
}
}
}

View File

@ -0,0 +1,200 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// Captures synchronous and asynchronous exceptions from the pipeline and generates HTML error responses.
/// </summary>
public class ErrorPageMiddleware
{
private readonly RequestDelegate _next;
private readonly ErrorPageOptions _options;
/// <summary>
/// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
/// </summary>
/// <param name="next"></param>
/// <param name="options"></param>
/// <param name="isDevMode"></param>
public ErrorPageMiddleware(RequestDelegate next, ErrorPageOptions options, bool isDevMode)
{
if (next == null)
{
throw new ArgumentNullException("next");
}
if (options == null)
{
throw new ArgumentNullException("options");
}
if (isDevMode)
{
options.SetDefaultVisibility(isVisible: true);
}
_next = next;
_options = options;
}
/// <summary>
/// Process an individual request.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "For diagnostics")]
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
try
{
DisplayException(context, ex);
return;
}
catch (Exception)
{
// If there's a Exception while generating the error page, re-throw the original exception.
}
throw;
}
}
// Assumes the response headers have not been sent. If they have, still attempt to write to the body.
private void DisplayException(HttpContext context, Exception ex)
{
var request = context.Request;
ErrorPageModel model = new ErrorPageModel()
{
Options = _options,
};
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)
{
model.Environment = context;
}*/
var errorPage = new ErrorPage() { Model = model };
errorPage.Execute(context);
}
private IEnumerable<ErrorDetails> GetErrorDetails(Exception ex, bool showSource)
{
for (Exception scan = ex; scan != null; scan = scan.InnerException)
{
yield return new ErrorDetails
{
Error = scan,
StackFrames = StackFrames(scan, showSource)
};
}
}
private IEnumerable<StackFrame> StackFrames(Exception ex, bool showSource)
{
var stackTrace = ex.StackTrace;
if (!string.IsNullOrEmpty(stackTrace))
{
var heap = new Chunk { Text = stackTrace + Environment.NewLine, End = stackTrace.Length + 2 };
for (Chunk line = heap.Advance(Environment.NewLine); line.HasValue; line = heap.Advance(Environment.NewLine))
{
yield return StackFrame(line, showSource);
}
}
}
private StackFrame StackFrame(Chunk line, bool showSource)
{
line.Advance(" at ");
string function = line.Advance(" in ").ToString();
string file = line.Advance(":line ").ToString();
int lineNumber = line.ToInt32();
return string.IsNullOrEmpty(file)
? LoadFrame(line.ToString(), string.Empty, 0, showSource)
: LoadFrame(function, file, lineNumber, showSource);
}
private StackFrame LoadFrame(string function, string file, int lineNumber, bool showSource)
{
var frame = new StackFrame { Function = function, File = file, Line = lineNumber };
if (showSource && File.Exists(file))
{
IEnumerable<string> code = File.ReadLines(file);
frame.PreContextLine = Math.Max(lineNumber - _options.SourceCodeLineCount, 1);
frame.PreContextCode = code.Skip(frame.PreContextLine - 1).Take(lineNumber - frame.PreContextLine).ToArray();
frame.ContextCode = code.Skip(lineNumber - 1).FirstOrDefault();
frame.PostContextCode = code.Skip(lineNumber).Take(_options.SourceCodeLineCount).ToArray();
}
return frame;
}
internal class Chunk
{
public string Text { get; set; }
public int Start { get; set; }
public int End { get; set; }
public bool HasValue
{
get { return Text != null; }
}
public Chunk Advance(string delimiter)
{
int indexOf = HasValue ? Text.IndexOf(delimiter, Start, End - Start, StringComparison.Ordinal) : -1;
if (indexOf < 0)
{
return new Chunk();
}
var chunk = new Chunk { Text = Text, Start = Start, End = indexOf };
Start = indexOf + delimiter.Length;
return chunk;
}
public override string ToString()
{
return HasValue ? Text.Substring(Start, End - Start) : string.Empty;
}
public int ToInt32()
{
int value;
return HasValue && Int32.TryParse(
Text.Substring(Start, End - Start),
NumberStyles.Integer,
CultureInfo.InvariantCulture,
out value) ? value : 0;
}
}
}
}

View File

@ -0,0 +1,117 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// Options for the ErrorPageMiddleware
/// </summary>
public class ErrorPageOptions
{
private bool _defaultVisibility;
private bool? _showExceptionDetails;
private bool? _showSourceCode;
private bool? _showQuery;
private bool? _showCookies;
private bool? _showHeaders;
private bool? _showEnvironment;
/// <summary>
/// Create an instance with the default options settings.
/// </summary>
public ErrorPageOptions()
{
SourceCodeLineCount = 6;
}
/// <summary>
/// Returns a new instance of ErrorPageOptions with all visibility options enabled by default.
/// </summary>
public static ErrorPageOptions ShowAll
{
get
{
// We don't use a static instance because it's mutable.
return 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 { return _showExceptionDetails ?? _defaultVisibility; }
set { _showExceptionDetails = value; }
}
/// <summary>
/// Enabled the display of local source code around exception stack frames.
/// </summary>
public bool ShowSourceCode
{
get { return _showSourceCode ?? _defaultVisibility; }
set { _showSourceCode = value; }
}
/// <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
/// 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 { return _showQuery ?? _defaultVisibility; }
set { _showQuery = value; }
}
/// <summary>
/// Enables the enumeration of any parsed request cookies.
/// </summary>
public bool ShowCookies
{
get { return _showCookies ?? _defaultVisibility; }
set { _showCookies = value; }
}
/// <summary>
/// Enables the enumeration of the request headers.
/// </summary>
public bool ShowHeaders
{
get { return _showHeaders ?? _defaultVisibility; }
set { _showHeaders = value; }
}
/// <summary>
/// Enables the enumeration of the OWIN environment values.
/// </summary>
public bool ShowEnvironment
{
get { return _showEnvironment ?? _defaultVisibility; }
set { _showEnvironment = value; }
}
/// <summary>
/// Sets the default visibility for options not otherwise specified.
/// </summary>
/// <param name="isVisible"></param>
public void SetDefaultVisibility(bool isVisible)
{
_defaultVisibility = isVisible;
}
}
}

View File

@ -0,0 +1,315 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.33440
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.AspNet.Diagnostics {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNet.Diagnostics.Resources", System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(Resources)).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to You are seeing this page because DiagnosticsPageMiddleware was added to your web application..
/// </summary>
internal static string DiagnosticsPageHtml_Information {
get {
return ResourceManager.GetString("DiagnosticsPageHtml_Information", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Test Error Message.
/// </summary>
internal static string DiagnosticsPageHtml_TestErrorMessage {
get {
return ResourceManager.GetString("DiagnosticsPageHtml_TestErrorMessage", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Test Error Page.
/// </summary>
internal static string DiagnosticsPageHtml_TestErrorSection {
get {
return ResourceManager.GetString("DiagnosticsPageHtml_TestErrorSection", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Diagnostics Page.
/// </summary>
internal static string DiagnosticsPageHtml_Title {
get {
return ResourceManager.GetString("DiagnosticsPageHtml_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cookies.
/// </summary>
internal static string ErrorPageHtml_CookiesButton {
get {
return ResourceManager.GetString("ErrorPageHtml_CookiesButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Enable development mode or ErrorPageOptions.ShowExceptionDetails for additional information..
/// </summary>
internal static string ErrorPageHtml_EnableShowExceptions {
get {
return ResourceManager.GetString("ErrorPageHtml_EnableShowExceptions", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Environment.
/// </summary>
internal static string ErrorPageHtml_EnvironmentButton {
get {
return ResourceManager.GetString("ErrorPageHtml_EnvironmentButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Headers.
/// </summary>
internal static string ErrorPageHtml_HeadersButton {
get {
return ResourceManager.GetString("ErrorPageHtml_HeadersButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No cookie data..
/// </summary>
internal static string ErrorPageHtml_NoCookieData {
get {
return ResourceManager.GetString("ErrorPageHtml_NoCookieData", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No header data..
/// </summary>
internal static string ErrorPageHtml_NoHeaderData {
get {
return ResourceManager.GetString("ErrorPageHtml_NoHeaderData", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No QueryString data..
/// </summary>
internal static string ErrorPageHtml_NoQueryStringData {
get {
return ResourceManager.GetString("ErrorPageHtml_NoQueryStringData", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Query.
/// </summary>
internal static string ErrorPageHtml_QueryButton {
get {
return ResourceManager.GetString("ErrorPageHtml_QueryButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Stack.
/// </summary>
internal static string ErrorPageHtml_StackButton {
get {
return ResourceManager.GetString("ErrorPageHtml_StackButton", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Internal Server Error.
/// </summary>
internal static string ErrorPageHtml_Title {
get {
return ResourceManager.GetString("ErrorPageHtml_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An unhandled exception occurred while processing the request..
/// </summary>
internal static string ErrorPageHtml_UnhandledException {
get {
return ResourceManager.GetString("ErrorPageHtml_UnhandledException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unknown location.
/// </summary>
internal static string ErrorPageHtml_UnknownLocation {
get {
return ResourceManager.GetString("ErrorPageHtml_UnknownLocation", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value.
/// </summary>
internal static string ErrorPageHtml_ValueColumn {
get {
return ResourceManager.GetString("ErrorPageHtml_ValueColumn", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Variable.
/// </summary>
internal static string ErrorPageHtml_VariableColumn {
get {
return ResourceManager.GetString("ErrorPageHtml_VariableColumn", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The path must start with a &apos;/&apos;..
/// </summary>
internal static string Exception_PathMustStartWithSlash {
get {
return ResourceManager.GetString("Exception_PathMustStartWithSlash", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Welcome.
/// </summary>
internal static string WelcomeHeader {
get {
return ResourceManager.GetString("WelcomeHeader", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Learn more about the Microsoft OWIN components.
/// </summary>
internal static string WelcomeLearnMicrosoftOwin {
get {
return ResourceManager.GetString("WelcomeLearnMicrosoftOwin", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Learn more about OWIN.
/// </summary>
internal static string WelcomeLearnOwin {
get {
return ResourceManager.GetString("WelcomeLearnOwin", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Browser.
/// </summary>
internal static string WelcomePageImageText_Browser {
get {
return ResourceManager.GetString("WelcomePageImageText_Browser", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Learn More.
/// </summary>
internal static string WelcomePageImageText_LearnMore {
get {
return ResourceManager.GetString("WelcomePageImageText_LearnMore", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Light Bulb.
/// </summary>
internal static string WelcomePageImageText_LightBulb {
get {
return ResourceManager.GetString("WelcomePageImageText_LightBulb", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Skyline.
/// </summary>
internal static string WelcomePageImageText_Skyline {
get {
return ResourceManager.GetString("WelcomePageImageText_Skyline", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Your OWIN application has been successfully started.
/// </summary>
internal static string WelcomeStarted {
get {
return ResourceManager.GetString("WelcomeStarted", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Your OWIN application has been successfully started..
/// </summary>
internal static string WelcomeTitle {
get {
return ResourceManager.GetString("WelcomeTitle", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,212 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DiagnosticsPageHtml_Information" xml:space="preserve">
<value>You are seeing this page because DiagnosticsPageMiddleware was added to your web application.</value>
</data>
<data name="DiagnosticsPageHtml_TestErrorMessage" xml:space="preserve">
<value>Test Error Message</value>
</data>
<data name="DiagnosticsPageHtml_TestErrorSection" xml:space="preserve">
<value>Test Error Page</value>
</data>
<data name="DiagnosticsPageHtml_Title" xml:space="preserve">
<value>Diagnostics Page</value>
</data>
<data name="ErrorPageHtml_CookiesButton" xml:space="preserve">
<value>Cookies</value>
<comment>as in http request cookies</comment>
</data>
<data name="ErrorPageHtml_EnableShowExceptions" xml:space="preserve">
<value>Enable development mode or ErrorPageOptions.ShowExceptionDetails for additional information.</value>
</data>
<data name="ErrorPageHtml_EnvironmentButton" xml:space="preserve">
<value>Environment</value>
<comment>as in OWIN environment dictionary</comment>
</data>
<data name="ErrorPageHtml_HeadersButton" xml:space="preserve">
<value>Headers</value>
<comment>as in http request headers</comment>
</data>
<data name="ErrorPageHtml_NoCookieData" xml:space="preserve">
<value>No cookie data.</value>
</data>
<data name="ErrorPageHtml_NoHeaderData" xml:space="preserve">
<value>No header data.</value>
</data>
<data name="ErrorPageHtml_NoQueryStringData" xml:space="preserve">
<value>No QueryString data.</value>
</data>
<data name="ErrorPageHtml_QueryButton" xml:space="preserve">
<value>Query</value>
<comment>as in a request url query string</comment>
</data>
<data name="ErrorPageHtml_StackButton" xml:space="preserve">
<value>Stack</value>
<comment>as in an exception's call stack</comment>
</data>
<data name="ErrorPageHtml_Title" xml:space="preserve">
<value>Internal Server Error</value>
</data>
<data name="ErrorPageHtml_UnhandledException" xml:space="preserve">
<value>An unhandled exception occurred while processing the request.</value>
</data>
<data name="ErrorPageHtml_UnknownLocation" xml:space="preserve">
<value>Unknown location</value>
<comment>when a stack source code location is not known</comment>
</data>
<data name="ErrorPageHtml_ValueColumn" xml:space="preserve">
<value>Value</value>
<comment>as in dictionary value</comment>
</data>
<data name="ErrorPageHtml_VariableColumn" xml:space="preserve">
<value>Variable</value>
<comment>as in dictionary key</comment>
</data>
<data name="Exception_PathMustStartWithSlash" xml:space="preserve">
<value>The path must start with a '/'.</value>
</data>
<data name="WelcomeHeader" xml:space="preserve">
<value>Welcome</value>
</data>
<data name="WelcomeLearnMicrosoftOwin" xml:space="preserve">
<value>Learn more about the Microsoft OWIN components</value>
</data>
<data name="WelcomeLearnOwin" xml:space="preserve">
<value>Learn more about OWIN</value>
</data>
<data name="WelcomePageImageText_Browser" xml:space="preserve">
<value>Browser</value>
</data>
<data name="WelcomePageImageText_LearnMore" xml:space="preserve">
<value>Learn More</value>
</data>
<data name="WelcomePageImageText_LightBulb" xml:space="preserve">
<value>Light Bulb</value>
</data>
<data name="WelcomePageImageText_Skyline" xml:space="preserve">
<value>Skyline</value>
</data>
<data name="WelcomeStarted" xml:space="preserve">
<value>Your OWIN application has been successfully started</value>
</data>
<data name="WelcomeTitle" xml:space="preserve">
<value>Your OWIN application has been successfully started.</value>
</data>
</root>

View File

@ -0,0 +1,442 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using Microsoft.AspNet.Abstractions;
using System;
using System.Globalization;
using System.IO;
using System.Net;
namespace Microsoft.AspNet.Diagnostics.Views
{
/// <summary>
/// Infrastructure
/// </summary>
public abstract class BaseView
{
/// <summary>
/// The request context
/// </summary>
protected HttpContext Context { get; private set; }
/// <summary>
/// The request
/// </summary>
protected HttpRequest Request { get; private set; }
/// <summary>
/// The response
/// </summary>
protected HttpResponse Response { get; private set; }
/// <summary>
/// The output stream
/// </summary>
protected StreamWriter Output { get; private set; }
/// <summary>
/// Execute an individual request
/// </summary>
/// <param name="context"></param>
public void Execute(HttpContext context)
{
Context = context;
Request = Context.Request;
Response = Context.Response;
Output = new StreamWriter(Response.Body);
Execute();
Output.Dispose();
}
/// <summary>
/// Execute an individual request
/// </summary>
public abstract void Execute();
/// <summary>
/// Write the given value directly to the output
/// </summary>
/// <param name="value"></param>
protected void WriteLiteral(string value)
{
Output.Write(value);
}
/// <summary>
///
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <param name="name"></param>
/// <param name="leader"></param>
/// <param name="trailer"></param>
/// <param name="part1"></param>
protected void WriteAttribute<T1>(
string name,
Tuple<string, int> leader,
Tuple<string, int> trailer,
Tuple<Tuple<string, int>, Tuple<T1, int>, bool> part1)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (leader == null)
{
throw new ArgumentNullException("leader");
}
if (trailer == null)
{
throw new ArgumentNullException("trailer");
}
if (part1 == null)
{
throw new ArgumentNullException("part1");
}
WriteLiteral(leader.Item1);
WriteLiteral(part1.Item1.Item1);
Write(part1.Item2.Item1);
WriteLiteral(trailer.Item1);
}
/// <summary>
///
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <param name="name"></param>
/// <param name="leader"></param>
/// <param name="trailer"></param>
/// <param name="part1"></param>
/// <param name="part2"></param>
protected void WriteAttribute<T1, T2>(
string name,
Tuple<string, int> leader,
Tuple<string, int> trailer,
Tuple<Tuple<string, int>, Tuple<T1, int>, bool> part1,
Tuple<Tuple<string, int>, Tuple<T2, int>, bool> part2)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (leader == null)
{
throw new ArgumentNullException("leader");
}
if (trailer == null)
{
throw new ArgumentNullException("trailer");
}
if (part1 == null)
{
throw new ArgumentNullException("part1");
}
if (part2 == null)
{
throw new ArgumentNullException("part2");
}
WriteLiteral(leader.Item1);
WriteLiteral(part1.Item1.Item1);
Write(part1.Item2.Item1);
WriteLiteral(part2.Item1.Item1);
Write(part2.Item2.Item1);
WriteLiteral(trailer.Item1);
}
/// <summary>
///
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <typeparam name="T3"></typeparam>
/// <param name="name"></param>
/// <param name="leader"></param>
/// <param name="trailer"></param>
/// <param name="part1"></param>
/// <param name="part2"></param>
/// <param name="part3"></param>
protected void WriteAttribute<T1, T2, T3>(
string name,
Tuple<string, int> leader,
Tuple<string, int> trailer,
Tuple<Tuple<string, int>, Tuple<T1, int>, bool> part1,
Tuple<Tuple<string, int>, Tuple<T2, int>, bool> part2,
Tuple<Tuple<string, int>, Tuple<T3, int>, bool> part3)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (leader == null)
{
throw new ArgumentNullException("leader");
}
if (trailer == null)
{
throw new ArgumentNullException("trailer");
}
if (part1 == null)
{
throw new ArgumentNullException("part1");
}
if (part2 == null)
{
throw new ArgumentNullException("part2");
}
if (part3 == null)
{
throw new ArgumentNullException("part3");
}
WriteLiteral(leader.Item1);
WriteLiteral(part1.Item1.Item1);
Write(part1.Item2.Item1);
WriteLiteral(part2.Item1.Item1);
Write(part2.Item2.Item1);
WriteLiteral(part3.Item1.Item1);
Write(part3.Item2.Item1);
WriteLiteral(trailer.Item1);
}
/// <summary>
///
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <typeparam name="T3"></typeparam>
/// <typeparam name="T4"></typeparam>
/// <param name="name"></param>
/// <param name="leader"></param>
/// <param name="trailer"></param>
/// <param name="part1"></param>
/// <param name="part2"></param>
/// <param name="part3"></param>
/// <param name="part4"></param>
protected void WriteAttribute<T1, T2, T3, T4>(
string name,
Tuple<string, int> leader,
Tuple<string, int> trailer,
Tuple<Tuple<string, int>, Tuple<T1, int>, bool> part1,
Tuple<Tuple<string, int>, Tuple<T2, int>, bool> part2,
Tuple<Tuple<string, int>, Tuple<T3, int>, bool> part3,
Tuple<Tuple<string, int>, Tuple<T4, int>, bool> part4)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (leader == null)
{
throw new ArgumentNullException("leader");
}
if (trailer == null)
{
throw new ArgumentNullException("trailer");
}
if (part1 == null)
{
throw new ArgumentNullException("part1");
}
if (part2 == null)
{
throw new ArgumentNullException("part2");
}
if (part3 == null)
{
throw new ArgumentNullException("part3");
}
if (part4 == null)
{
throw new ArgumentNullException("part4");
}
WriteLiteral(leader.Item1);
WriteLiteral(part1.Item1.Item1);
Write(part1.Item2.Item1);
WriteLiteral(part2.Item1.Item1);
Write(part2.Item2.Item1);
WriteLiteral(part3.Item1.Item1);
Write(part3.Item2.Item1);
WriteLiteral(part4.Item1.Item1);
Write(part4.Item2.Item1);
WriteLiteral(trailer.Item1);
}
/// <summary>
///
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <typeparam name="T3"></typeparam>
/// <typeparam name="T4"></typeparam>
/// <typeparam name="T5"></typeparam>
/// <param name="name"></param>
/// <param name="leader"></param>
/// <param name="trailer"></param>
/// <param name="part1"></param>
/// <param name="part2"></param>
/// <param name="part3"></param>
/// <param name="part4"></param>
/// <param name="part5"></param>
protected void WriteAttribute<T1, T2, T3, T4, T5>(
string name,
Tuple<string, int> leader,
Tuple<string, int> trailer,
Tuple<Tuple<string, int>, Tuple<T1, int>, bool> part1,
Tuple<Tuple<string, int>, Tuple<T2, int>, bool> part2,
Tuple<Tuple<string, int>, Tuple<T3, int>, bool> part3,
Tuple<Tuple<string, int>, Tuple<T4, int>, bool> part4,
Tuple<Tuple<string, int>, Tuple<T5, int>, bool> part5)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (leader == null)
{
throw new ArgumentNullException("leader");
}
if (trailer == null)
{
throw new ArgumentNullException("trailer");
}
if (part1 == null)
{
throw new ArgumentNullException("part1");
}
if (part2 == null)
{
throw new ArgumentNullException("part2");
}
if (part3 == null)
{
throw new ArgumentNullException("part3");
}
if (part4 == null)
{
throw new ArgumentNullException("part4");
}
if (part5 == null)
{
throw new ArgumentNullException("part5");
}
WriteLiteral(leader.Item1);
WriteLiteral(part1.Item1.Item1);
Write(part1.Item2.Item1);
WriteLiteral(part2.Item1.Item1);
Write(part2.Item2.Item1);
WriteLiteral(part3.Item1.Item1);
Write(part3.Item2.Item1);
WriteLiteral(part4.Item1.Item1);
Write(part4.Item2.Item1);
WriteLiteral(part5.Item1.Item1);
Write(part5.Item2.Item1);
WriteLiteral(trailer.Item1);
}
/// <summary>
///
/// </summary>
/// <typeparam name="T1"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <typeparam name="T3"></typeparam>
/// <typeparam name="T4"></typeparam>
/// <typeparam name="T5"></typeparam>
/// <typeparam name="T6"></typeparam>
/// <param name="name"></param>
/// <param name="leader"></param>
/// <param name="trailer"></param>
/// <param name="part1"></param>
/// <param name="part2"></param>
/// <param name="part3"></param>
/// <param name="part4"></param>
/// <param name="part5"></param>
/// <param name="part6"></param>
protected void WriteAttribute<T1, T2, T3, T4, T5, T6>(
string name,
Tuple<string, int> leader,
Tuple<string, int> trailer,
Tuple<Tuple<string, int>, Tuple<T1, int>, bool> part1,
Tuple<Tuple<string, int>, Tuple<T2, int>, bool> part2,
Tuple<Tuple<string, int>, Tuple<T3, int>, bool> part3,
Tuple<Tuple<string, int>, Tuple<T4, int>, bool> part4,
Tuple<Tuple<string, int>, Tuple<T5, int>, bool> part5,
Tuple<Tuple<string, int>, Tuple<T6, int>, bool> part6)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (leader == null)
{
throw new ArgumentNullException("leader");
}
if (trailer == null)
{
throw new ArgumentNullException("trailer");
}
if (part1 == null)
{
throw new ArgumentNullException("part1");
}
if (part2 == null)
{
throw new ArgumentNullException("part2");
}
if (part3 == null)
{
throw new ArgumentNullException("part3");
}
if (part4 == null)
{
throw new ArgumentNullException("part4");
}
if (part5 == null)
{
throw new ArgumentNullException("part5");
}
if (part6 == null)
{
throw new ArgumentNullException("part6");
}
WriteLiteral(leader.Item1);
WriteLiteral(part1.Item1.Item1);
Write(part1.Item2.Item1);
WriteLiteral(part2.Item1.Item1);
Write(part2.Item2.Item1);
WriteLiteral(part3.Item1.Item1);
Write(part3.Item2.Item1);
WriteLiteral(part4.Item1.Item1);
Write(part4.Item2.Item1);
WriteLiteral(part5.Item1.Item1);
Write(part5.Item2.Item1);
WriteLiteral(part6.Item1.Item1);
Write(part6.Item2.Item1);
WriteLiteral(trailer.Item1);
}
/// <summary>
/// Html encode and write
/// </summary>
/// <param name="value"></param>
private void WriteEncoded(string value)
{
Output.Write(WebUtility.HtmlEncode(value));
}
/// <summary>
/// Convert to string and html encode
/// </summary>
/// <param name="value"></param>
protected void Write(object value)
{
WriteEncoded(Convert.ToString(value, CultureInfo.InvariantCulture));
}
/// <summary>
/// Html encode and write
/// </summary>
/// <param name="value"></param>
protected void Write(string value)
{
WriteEncoded(value);
}
}
}

View File

@ -0,0 +1,133 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18213
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.AspNet.Diagnostics.Views {
#line 1 "DiagnosticsPage.cshtml"
using System;
#line default
#line hidden
#line 2 "DiagnosticsPage.cshtml"
using System.Globalization;
#line default
#line hidden
public class DiagnosticsPage : Microsoft.AspNet.Diagnostics.Views.BaseView {
#line hidden
public DiagnosticsPage() {
}
public override void Execute() {
#line 3 "DiagnosticsPage.cshtml"
Response.ContentType = "text/html";
string error = Request.Query.Get("error");
if (!string.IsNullOrWhiteSpace(error))
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "User requested error '{0}'", error));
}
#line default
#line hidden
WriteLiteral("\r\n<!DOCTYPE html>\r\n\r\n<html");
WriteLiteral(" lang=\"en\"");
WriteLiteral(" xmlns=\"http://www.w3.org/1999/xhtml\"");
WriteLiteral(">\r\n<head>\r\n <meta");
WriteLiteral(" charset=\"utf-8\"");
WriteLiteral(" />\r\n <title>");
#line 16 "DiagnosticsPage.cshtml"
Write(Resources.DiagnosticsPageHtml_Title);
#line default
#line hidden
WriteLiteral("</title>\r\n</head>\r\n<body>\r\n <div");
WriteLiteral(" class=\"main\"");
WriteLiteral(">\r\n <h1>");
#line 20 "DiagnosticsPage.cshtml"
Write(Resources.DiagnosticsPageHtml_Title);
#line default
#line hidden
WriteLiteral("</h1>\r\n <p>");
#line 21 "DiagnosticsPage.cshtml"
Write(Resources.DiagnosticsPageHtml_Information);
#line default
#line hidden
WriteLiteral("</p>\r\n </div>\r\n <div");
WriteLiteral(" class=\"errors\"");
WriteLiteral(">\r\n <h2>");
#line 24 "DiagnosticsPage.cshtml"
Write(Resources.DiagnosticsPageHtml_TestErrorSection);
#line default
#line hidden
WriteLiteral("</h2>\r\n <p><a");
WriteAttribute("href", Tuple.Create(" href=\"", 767), Tuple.Create("\"", 858)
#line 25 "DiagnosticsPage.cshtml"
, Tuple.Create(Tuple.Create("", 774), Tuple.Create<System.Object, System.Int32>(Request.PathBase
#line default
#line hidden
, 774), false)
#line 25 "DiagnosticsPage.cshtml"
, Tuple.Create(Tuple.Create("", 791), Tuple.Create<System.Object, System.Int32>(Request.Path
#line default
#line hidden
, 791), false)
, Tuple.Create(Tuple.Create("", 804), Tuple.Create("?error=", 804), true)
#line 25 "DiagnosticsPage.cshtml"
, Tuple.Create(Tuple.Create("", 811), Tuple.Create<System.Object, System.Int32>(Resources.DiagnosticsPageHtml_TestErrorMessage
#line default
#line hidden
, 811), false)
);
WriteLiteral(">throw InvalidOperationException</a></p>\r\n </div>\r\n</body>\r\n</html>\r\n");
}
}
}

View File

@ -0,0 +1,28 @@
@using System
@using System.Globalization
@{
Response.ContentType = "text/html";
string error = Request.Query.Get("error");
if (!string.IsNullOrWhiteSpace(error))
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "User requested error '{0}'", error));
}
}
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>@Resources.DiagnosticsPageHtml_Title</title>
</head>
<body>
<div class="main">
<h1>@Resources.DiagnosticsPageHtml_Title</h1>
<p>@Resources.DiagnosticsPageHtml_Information</p>
</div>
<div class="errors">
<h2>@Resources.DiagnosticsPageHtml_TestErrorSection</h2>
<p><a href="@Request.PathBase@Request.Path?error=@Resources.DiagnosticsPageHtml_TestErrorMessage">throw InvalidOperationException</a></p>
</div>
</body>
</html>

View File

@ -0,0 +1,26 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Web.Razor" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Web.Razor" #>
<#@ import namespace="System.Web.Razor.Text" #>
<#@ output extension=".cs" #>
<#
var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
host.DefaultBaseClass = "Microsoft.Owin.Diagnostics.Views.BaseView";
var engine = new RazorTemplateEngine(host);
var path = Host.ResolvePath("DiagnosticsPage.cshtml");
var code = engine.GenerateCode(
new System.IO.StreamReader(path),
"DiagnosticsPage",
"Microsoft.Owin.Diagnostics.Views",
@"DiagnosticsPage.cshtml");
var provider = new Microsoft.CSharp.CSharpCodeProvider();
var writer = new System.IO.StringWriter();
provider.GenerateCodeFromCompileUnit(code.GeneratedCode, writer, null);
#>
<#=writer.ToString()#>

View File

@ -0,0 +1,39 @@
// <copyright file="ErrorDetails.cs" company="Microsoft Open Technologies, Inc.">
// Copyright 2011-2013 Microsoft Open Technologies, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Microsoft.AspNet.Diagnostics.Views
{
/// <summary>
/// Contains details for individual exception messages.
/// </summary>
public class ErrorDetails
{
/// <summary>
/// An individual exception
/// </summary>
public Exception Error { get; set; }
/// <summary>
/// The generated stack frames
/// </summary>
public IEnumerable<StackFrame> StackFrames { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,281 @@
@using System
@using System.Globalization
@using System.Linq
@using Views
@functions
{
/// <summary>
///
/// </summary>
public Views.ErrorPageModel Model { get; set; }
}
@{
Response.StatusCode = 500;
// TODO: Response.ReasonPhrase = "Internal Server Error";
Response.ContentType = "text/html";
Response.ContentLength = null; // Clear any prior Content-Length
string location = string.Empty;
}
<!DOCTYPE html>
<html lang="@System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>@Resources.ErrorPageHtml_Title</title>
<style>
@(@"[[ErrorPage.css]]")
</style>
</head>
<body>
<h1>@Resources.ErrorPageHtml_UnhandledException</h1>
@if (Model.Options.ShowExceptionDetails)
{
foreach (var errorDetail in Model.ErrorDetails)
{
<h2 class="titleerror">@errorDetail.Error.GetType().Name: @errorDetail.Error.Message</h2>
{
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))
{
<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>
}
</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>
}
@if (frame.Line != 0 && frame.ContextCode != null)
{
<div class="source">
@if (frame.PreContextCode != null)
{
<ol start="@frame.PreContextLine" class="collapsable">
@foreach (var line in frame.PreContextCode)
{
<li><span>@line</span></li>
}
</ol>
}
<ol start="@frame.Line" class="highlight">
<li><span>@frame.ContextCode</span></li></ol>
@if (frame.PostContextCode != null)
{
<ol start='@(frame.Line + 1)' class="collapsable">
@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>
}
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))
{
<tr>
<td>@kv.Key</td>
<td>@kv.Value</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>
<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>
}
@if (Model.Options.ShowEnvironment)
{
/* TODO:
<div id="environmentpage" class="page">
<table>
<thead>
<tr>
<th>@Resources.ErrorPageHtml_VariableColumn</th>
<th>@Resources.ErrorPageHtml_ValueColumn</th>
</tr>
</thead>
<tbody>
@foreach (var kv in Model.Environment.OrderBy(kv => kv.Key))
{
<tr>
<td>@kv.Key</td>
<td>@kv.Value</td>
</tr>
}
</tbody>
</table>
</div>
*/
}
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"></script>
<script type="text/javascript">
//<!--
@(@"[[ErrorPage.js]]")
//-->
</script>
</body>
</html>

View File

@ -0,0 +1,172 @@
body {
font-family: 'Segoe UI',Tahoma,Arial,Helvetica,sans-serif;
font-size: .813em;
line-height: 1.4em;
color: #222;
}
h1, h2, h3, h4, h5 {
/*font-family: 'Segoe UI',Tahoma,Arial,Helvetica,sans-serif;*/
font-weight: 100;
}
h1 {
color: #44525e;
margin: 15px 0 15px 0;
}
h2 {
margin: 10px 5px 0 0;
}
h3 {
color: #363636;
margin: 5px 5px 0 0;
}
code {
font-family: consolas, "Courier New", courier, monospace;
}
body .titleerror {
padding: 3px;
}
body .location {
margin: 3px 0 10px 30px;
}
#header {
font-size: 18px;
padding-left: 0px;
padding-right: 0px;
padding-top: 15px;
padding-bottom: 15px;
border-top: 1px #ddd solid;
border-bottom: 1px #ddd solid;
margin-bottom: 0px;
}
#header li {
display: inline;
margin: 5px;
padding: 5px;
color: #a0a0a0;
}
#header li:hover {
background: #A9E4F9;
color: #fff;
}
#header li.selected {
background: #44C5F2;
color: #fff;
}
#stackpage ul {
list-style: none;
padding-left: 0;
margin: 0;
/*border-bottom: 1px #ddd solid;*/
}
#stackpage .stackerror {
padding: 5px;
border-bottom: 1px #ddd solid;
}
#stackpage .stackerror:hover {
background-color: #f0f0f0;
}
#stackpage .frame:hover {
background-color: #f0f0f0;
text-decoration: none;
}
#stackpage .frame {
padding: 2px;
margin: 0 0 0 30px;
border-bottom: 1px #ddd solid;
}
#stackpage .frame h3 {
padding: 5px;
margin: 0;
}
#stackpage .source {
padding: 0px;
}
#stackpage .source ol li {
font-family: consolas, "Courier New", courier, monospace;
white-space: pre;
}
#stackpage .source ol.highlight li {
/*color: #e22;*/
/*font-weight: bold;*/
}
#stackpage .source ol.highlight li span {
/*color: #000;*/
}
#stackpage .frame:hover .source ol.highlight li span {
color: #fff;
background: #B20000;
}
#stackpage .source ol.collapsable li {
color: #888;
}
#stackpage .source ol.collapsable li span {
color: #606060;
}
.page table {
border-collapse: separate;
border-spacing: 0;
margin: 0 0 20px;
}
.page th {
vertical-align: bottom;
padding: 10px 5px 5px 5px;
font-weight: 400;
color: #a0a0a0;
text-align: left;
}
.page td {
padding: 3px 10px;
}
.page th, .page td {
border-right: 1px #ddd solid;
border-bottom: 1px #ddd solid;
border-left: 1px transparent solid;
border-top: 1px transparent solid;
box-sizing: border-box;
}
.page th:last-child, .page td:last-child {
border-right: 1px transparent solid;
}
.page td.length {
text-align: right;
}
a {
color: #1ba1e2;
text-decoration: none;
}
a:hover {
color: #13709e;
text-decoration: underline;
}

View File

@ -0,0 +1,36 @@

(function ($) {
$('.collapsable').hide();
$('.page').hide();
$('#stackpage').show();
$('.frame').click(function () {
$(this).children('.source').children('.collapsable').toggle('fast');
});
$('.frame').keypress(function (e) {
if (e.which == 13) {
$(this).children('.source').children('.collapsable').toggle('fast');
}
});
$('#header li').click(function () {
var unselected = $('#header .selected').removeClass('selected').attr('id');
var selected = $(this).addClass('selected').attr('id');
$('#' + unselected + 'page').hide();
$('#' + selected + 'page').show('fast');
});
$('#header li').keypress(function (e) {
if (e.which == 13) {
var unselected = $('#header .selected').removeClass('selected').attr('id');
var selected = $(this).addClass('selected').attr('id');
$('#' + unselected + 'page').hide();
$('#' + selected + 'page').show('fast');
}
});
})(jQuery);

View File

@ -0,0 +1,51 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Web.Razor" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Web.Razor" #>
<#@ import namespace="System.Web.Razor.Text" #>
<#@ output extension=".cs" #>
<#
var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
host.DefaultBaseClass = "Microsoft.Owin.Diagnostics.Views.BaseView";
var engine = new RazorTemplateEngine(host);
var path = Host.ResolvePath("ErrorPage.cshtml");
var code = engine.GenerateCode(
new System.IO.StreamReader(path),
"ErrorPage",
"Microsoft.Owin.Diagnostics.Views",
@"ErrorPage.cshtml");
var provider = new Microsoft.CSharp.CSharpCodeProvider();
var writer = new System.IO.StringWriter();
provider.GenerateCodeFromCompileUnit(code.GeneratedCode, writer, null);
var source = writer.ToString();
var startIndex = 0;
while(startIndex < source.Length)
{
var startMatch = @"Write(@""[[";
var startCode = @"WriteLiteral(@""";
var endMatch = @"]]"");";
var endCode = @""");";
startIndex = source.IndexOf(startMatch, startIndex);
if (startIndex == -1)
{
break;
}
var endIndex = source.IndexOf(endMatch, startIndex);
if (endIndex == -1)
{
break;
}
var fileName = source.Substring(startIndex + startMatch.Length, endIndex - (startIndex + startMatch.Length));
var replacement = File.ReadAllText(Host.ResolvePath(fileName)).Replace("\"", "\"\"");
source = source.Substring(0, startIndex) + startCode + replacement + endCode + source.Substring(endIndex + endMatch.Length);
startIndex = startIndex + startCode.Length + replacement.Length + endCode.Length;
}
#>
<#=source#>

View File

@ -0,0 +1,50 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using Microsoft.AspNet.Abstractions;
using System;
using System.Collections.Generic;
namespace Microsoft.AspNet.Diagnostics.Views
{
/// <summary>
/// Holds data to be displayed on the error page.
/// </summary>
public class ErrorPageModel
{
/// <summary>
/// Options for what output to display.
/// </summary>
public ErrorPageOptions Options { get; set; }
/// <summary>
/// Detailed information about each exception in the stack
/// </summary>
public IEnumerable<ErrorDetails> ErrorDetails { get; set; }
/// <summary>
/// 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
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public RequestCookieCollection Cookies { get; set; }
*/
/// <summary>
/// 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
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
public HttpContext Environment { get; set; }
*/
}
}

View File

@ -0,0 +1,47 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.AspNet.Diagnostics.Views
{
/// <summary>
/// Detailed exception stack information used to generate a view
/// </summary>
public class StackFrame
{
/// <summary>
/// Function containing instruction
/// </summary>
public string Function { get; set; }
/// <summary>
/// File containing the instruction
/// </summary>
public string File { get; set; }
/// <summary>
/// The line number of the instruction
/// </summary>
public int Line { get; set; }
/// <summary>
/// The line preceeding the frame line
/// </summary>
public int PreContextLine { get; set; }
/// <summary>
///
/// </summary>
public IEnumerable<string> PreContextCode { get; set; }
/// <summary>
///
/// </summary>
public string ContextCode { get; set; }
/// <summary>
///
/// </summary>
public IEnumerable<string> PostContextCode { get; set; }
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,50 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Web.Razor" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Web.Razor" #>
<#@ import namespace="System.Web.Razor.Text" #>
<#@ output extension=".cs" #>
<#
var host = new RazorEngineHost(new CSharpRazorCodeLanguage());
host.DefaultBaseClass = "Microsoft.Owin.Diagnostics.Views.BaseView";
var engine = new RazorTemplateEngine(host);
var path = Host.ResolvePath("WelcomePage.cshtml");
var code = engine.GenerateCode(
new System.IO.StreamReader(path),
"WelcomePage",
"Microsoft.Owin.Diagnostics.Views",
"WelcomePage.cshtml");
var provider = new Microsoft.CSharp.CSharpCodeProvider();
var writer = new System.IO.StringWriter();
provider.GenerateCodeFromCompileUnit(code.GeneratedCode, writer, null);
var source = writer.ToString();
var startIndex = 0;
while(startIndex < source.Length)
{
var startMatch = @"Write(@""[[";
var startCode = @"WriteLiteral(@""";
var endMatch = @"]]"");";
var endCode = @""");";
startIndex = source.IndexOf(startMatch, startIndex);
if (startIndex == -1)
{
break;
}
var endIndex = source.IndexOf(endMatch, startIndex);
if (endIndex == -1)
{
break;
}
var fileName = source.Substring(startIndex + startMatch.Length, endIndex - (startIndex + startMatch.Length));
var replacement = File.ReadAllText(Host.ResolvePath(fileName)).Replace("\"", "\"\"");
source = source.Substring(0, startIndex) + startCode + replacement + endCode + source.Substring(endIndex + endMatch.Length);
startIndex = startIndex + startCode.Length + replacement.Length + endCode.Length;
}
#>
<#=source#>

View File

@ -0,0 +1,62 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.Diagnostics;
namespace Microsoft.AspNet
{
/// <summary>
/// IBuilder extensions for the WelcomePageMiddleware.
/// </summary>
public static class WelcomePageExtensions
{
/// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given options.
/// </summary>
/// <param name="builder"></param>
/// <param name="options"></param>
/// <returns></returns>
public static IBuilder UseWelcomePage(this IBuilder builder, WelcomePageOptions options)
{
if (builder == null)
{
throw new ArgumentNullException("builder");
}
return builder.Use(next => new WelcomePageMiddleware(next, options).Invoke);
}
/// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given path.
/// </summary>
/// <param name="builder"></param>
/// <param name="path"></param>
/// <returns></returns>
public static IBuilder UseWelcomePage(this IBuilder builder, PathString path)
{
return UseWelcomePage(builder, new WelcomePageOptions { Path = path });
}
/// <summary>
/// Adds the WelcomePageMiddleware to the pipeline with the given path.
/// </summary>
/// <param name="builder"></param>
/// <param name="path"></param>
/// <returns></returns>
public static IBuilder UseWelcomePage(this IBuilder builder, string path)
{
return UseWelcomePage(builder, new WelcomePageOptions { Path = new PathString(path) });
}
/// <summary>
/// Adds the WelcomePageMiddleware to the pipeline.
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static IBuilder UseWelcomePage(this IBuilder builder)
{
return UseWelcomePage(builder, new WelcomePageOptions());
}
}
}

View File

@ -0,0 +1,58 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// This middleware provides a default web page for new applications.
/// </summary>
public class WelcomePageMiddleware
{
private readonly RequestDelegate _next;
private readonly WelcomePageOptions _options;
/// <summary>
/// Creates a default web page for new applications.
/// </summary>
/// <param name="next"></param>
/// <param name="options"></param>
public WelcomePageMiddleware(RequestDelegate next, WelcomePageOptions options)
{
if (next == null)
{
throw new ArgumentNullException("next");
}
if (options == null)
{
throw new ArgumentNullException("options");
}
_next = next;
_options = options;
}
/// <summary>
/// Process an individual request.
/// </summary>
/// <param name="environment"></param>
/// <returns></returns>
public Task Invoke(HttpContext context)
{
HttpRequest request = context.Request;
if (!_options.Path.HasValue || _options.Path == request.Path)
{
// Dynamically generated for LOC.
var welcomePage = new WelcomePage();
welcomePage.Execute(context);
return Task.FromResult(0);
}
return _next(context);
}
}
}

View File

@ -0,0 +1,17 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using Microsoft.AspNet.Abstractions;
namespace Microsoft.AspNet.Diagnostics
{
/// <summary>
/// Options for the WelcomePageMiddleware.
/// </summary>
public class WelcomePageOptions
{
/// <summary>
/// Specifies which requests paths will be responded to. Exact matches only. Leave null to handle all requests.
/// </summary>
public PathString Path { get; set; }
}
}

View File

@ -0,0 +1,32 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.DependencyInjection": "0.1-alpha-*",
"Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*",
"Microsoft.AspNet.PipelineCore": "0.1-alpha-*",
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
"Microsoft.AspNet.FeatureModel": "0.1-alpha-*"
},
"configurations": {
"net45": {},
"k10": {
"dependencies": {
"System.Collections": "4.0.0.0",
"System.ComponentModel": "4.0.0.0",
"System.Diagnostics.Debug": "4.0.10.0",
"System.Diagnostics.Tools": "4.0.0.0",
"System.Globalization": "4.0.10.0",
"System.IO": "4.0.0.0",
"System.IO.FileSystem": "4.0.0.0",
"System.IO.FileSystem.Primitives": "4.0.0.0",
"System.Linq": "4.0.0.0",
"System.Reflection": "4.0.10.0",
"System.Resources.ResourceManager": "4.0.0.0",
"System.Runtime": "4.0.20.0",
"System.Runtime.Extensions": "4.0.10.0",
"System.Threading": "4.0.0.0",
"System.Threading.Tasks": "4.0.0.0"
}
}
}
}