-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the ExceptionHandlerMiddleware to support getting the path to redirect to via LinkGenerator #4277
Comments
A design for this might look like:
It's a lambda because doing otherwise would require baking knowledge of an MVC extension method into diagnostics. This will require diagnostics to take a dependency on Routing (probably). This will add a @davidfowl @DamianEdwards thoughts? |
@rynowak in 3.0 routing will already move down to a level that diagnostics can use, right? |
Well that's a question we need to ask ourselves. Currently |
@DamianEdwards, can you please confirm whether you're ok with the design @rynowak proposed: if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler(link => link.GetPathByAction("Error", "Home"));
app.UseHsts();
} |
I was thinking about not even define it at all. Just have |
As part of 3.0 work we're planning to review all middleware to see what would benefit from integrating with endpoints. I think looking at generating URLs could happen in the same review, and it would be benefical to have a single strategy rather than introducing link generation to one middleware at a time. |
To make sure I understand, MVC would add extension methods to link.GetPathForAction(string actionName, string controllerName);
link.GetPathForAction(string actionName, string controllerName, params object[] routeArgs);
link.GetPathForPage(string pageName);
link.GetPathForPage(string pageName, string handlerName);
link.GetPathForPage(string pageName, params object[] routeArgs);
link.GetPathForPage(string pageName, string handlerName, params object[] routeArgs); Then we'd either need Diagnostics to take a dependency on Routing, or create a new package that depends on both, to add the middleware extension methods like: app.UseExceptionHandler(Func<LinkGenerator, string> pathSelector); Is that right? I don't mind @mkArtakMSFT's idea about adding a meta-data convention to the default overload too, falling back to the default we already have today (throwing if both the handler and handler path are |
This is already done 😋 I like the I think the no-args thing is pretty interesting, and I feel good about it if it's for 3.0. In a 2.2 context it would be pretty hard to explain to a user because it will introduce a bunch of new concepts that will only be used for this feature (in 2.2). I think if we do this one we should do both. -- I also don't want to design this feature in a vacuum. As @JamesNK pointed out, one of his next tasks is to review all of the other candidates for using link generation in middleware. |
Careful with the func, they can make inline lambda's really confusing to write when there's multiple overloads. |
This would be a different arity though, so it should be alright |
Only in that it has a return value, which is really ambiguous when you're not using the brackets |
oh yeah :-/ ok so this would have to have a different name then. |
Thanks for contacting us. We're moving this issue to the |
Today, the web app project templates have a block like this:
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
The text was updated successfully, but these errors were encountered: