dotnet / dotnet/aspnetcore

Update the ExceptionHandlerMiddleware to support getting the path to redirect to via LinkGenerator

Open
#4,277 14 comments 0 reactions 0 assignees View on GitHub
affected-few area-mvc enhancement feature-routing Needs: Design severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

Today, the web app project templates have a block like this:

``` c#
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
```

Note the string literal parameter in the call to `app.UseExceptionHandler`. That string (in this case) is the path to a Razor Page (*~/Pages/Error.cshtml*), but as it's a string literal, if the page's route changes (e.g. because its name changes or another route for it is configured) this string path will now be wrong.

It would be great if the middleware allowed the user to specify the path using a `LinkGenerator` (expression?) such that strongly-typed paths to MVC endpoints in 2.2 (and in 3.0 any endpoint) could be done.

@rynowak @JamesNK

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.