Added IExceptionHandlerPathFeature interface.

This commit is contained in:
Mikael Mengistu 2016-09-12 14:50:59 -07:00
parent c037a577b0
commit 3a868d87a2
3 changed files with 24 additions and 3 deletions

View File

@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Diagnostics
{
/// <summary>
/// Represents an exception handler with the original path of the request.
/// </summary>
public interface IExceptionHandlerPathFeature : IExceptionHandlerFeature
{
/// <summary>
/// The portion of the request path that identifies the requested resource. The value
/// is un-escaped.
/// </summary>
string Path { get; }
}
}

View File

@ -5,8 +5,10 @@ using System;
namespace Microsoft.AspNetCore.Diagnostics namespace Microsoft.AspNetCore.Diagnostics
{ {
public class ExceptionHandlerFeature : IExceptionHandlerFeature public class ExceptionHandlerFeature : IExceptionHandlerPathFeature
{ {
public Exception Error { get; set; } public Exception Error { get; set; }
public string Path { get; set; }
} }
} }

View File

@ -22,8 +22,8 @@ namespace Microsoft.AspNetCore.Diagnostics
private readonly DiagnosticSource _diagnosticSource; private readonly DiagnosticSource _diagnosticSource;
public ExceptionHandlerMiddleware( public ExceptionHandlerMiddleware(
RequestDelegate next, RequestDelegate next,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IOptions<ExceptionHandlerOptions> options, IOptions<ExceptionHandlerOptions> options,
DiagnosticSource diagnosticSource) DiagnosticSource diagnosticSource)
{ {
@ -65,8 +65,10 @@ namespace Microsoft.AspNetCore.Diagnostics
var exceptionHandlerFeature = new ExceptionHandlerFeature() var exceptionHandlerFeature = new ExceptionHandlerFeature()
{ {
Error = ex, Error = ex,
Path = originalPath.Value,
}; };
context.Features.Set<IExceptionHandlerFeature>(exceptionHandlerFeature); context.Features.Set<IExceptionHandlerFeature>(exceptionHandlerFeature);
context.Features.Set<IExceptionHandlerPathFeature>(exceptionHandlerFeature);
context.Response.StatusCode = 500; context.Response.StatusCode = 500;
context.Response.OnStarting(_clearCacheHeadersDelegate, context.Response); context.Response.OnStarting(_clearCacheHeadersDelegate, context.Response);