Skip to content

How to retrieve the original endpoint from within a exception handler? #60765

Closed Answered by nicystalker
nicystalker asked this question in Q&A
Discussion options

You must be logged in to vote

To achieve something similar to the internal __OriginalEndpoint I created a middleware that checks for a specific part of the route pattern, since it has a predictable prefix:

app.Use((context, next) =>
{
    if (context.GetEndpoint() is RouteEndpoint endpoint &&
        endpoint.RoutePattern.PathSegments[0].Parts[0] is RoutePatternLiteralPart { Content: "api" })
    {
        context.Items.Add("OriginalEndpoint", endpoint);
    }

    return next(context);
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nicystalker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant