Update path information for status code pages (#9390)

pull/9395/head
Luke Latham 2018-11-01 18:13:04 -05:00 committed by GitHub
parent 55c42642a6
commit 90d05ded84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 6 deletions

View File

@ -1,10 +1,10 @@
---
title: Handle errors in ASP.NET Core
author: ardalis
author: tdykstra
description: Discover how to handle errors in ASP.NET Core apps.
ms.author: tdykstra
ms.custom: mvc
ms.date: 07/05/2018
ms.date: 11/01/2018
uid: fundamentals/error-handling
---
# Handle errors in ASP.NET Core
@ -113,17 +113,28 @@ The middleware supports several extension methods. One method takes a lambda exp
[!code-csharp[](error-handling/samples/2.x/ErrorHandlingSample/Startup.cs?name=snippet_StatusCodePages)]
Another method takes a content type and format string:
An overload of `UseStatusCodePages` takes a content type and format string:
```csharp
app.UseStatusCodePages("text/plain", "Status code page, status code: {0}");
```
### Redirect re-execute extension methods
There are also redirect and re-execute extension methods. The redirect method sends a *302 Found* status code to the client and redirects the client to the provided location URL template. The template may include a `{0}` placeholder for the status code. URLs starting with `~` have the base path prepended. A URL that doesn't start with `~` is used as is.
<xref:Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithRedirects*>:
* Sends a *302 - Found* status code to the client.
* Redirects the client to the location provided in the URL template.
The template may include a `{0}` placeholder for the status code. The template must start with a forward slash (`/`).
[!code-csharp[](error-handling/samples/2.x/ErrorHandlingSample/Startup.cs?name=snippet_StatusCodePagesWithRedirect)]
The re-execute method returns the original status code to the client and specifies that the response body should be generated by re-executing the request pipeline using an alternate path. This path may contain a `{0}` placeholder for the status code:
<xref:Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute*>:
* Returns the original status code to the client.
* Specifies that the response body should be generated by re-executing the request pipeline using an alternate path.
The template may include a `{0}` placeholder for the status code. The template must start with a forward slash (`/`).
```csharp
app.UseStatusCodePagesWithReExecute("/error/{0}");
@ -140,7 +151,7 @@ if (statusCodePagesFeature != null)
}
```
If using a `UseStatusCodePages*` overload that points to an endpoint within the app, create an MVC view or Razor Page for the endpoint. For example, the [dotnet new](/dotnet/core/tools/dotnet-new) template for a Razor Pages app produces the following page and page model class:
To use a `UseStatusCodePages*` overload that points to an endpoint within the app, create an MVC view or Razor Page for the endpoint. For example, the [dotnet new](/dotnet/core/tools/dotnet-new) template for a Razor Pages app produces the following page and page model class:
*Error.cshtml*: