As off .Net 6, a middleware containing context.Request.Path = "/error/500" no longer rewrites the new path to handle the exception. Is there a new way to set a request path in .Net 6 within the middleware?
Thank you!
Attached is an example code:
public class ErrorHandlingMiddleware
{
private readonly RequestDelegate next;
public ErrorHandlingMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await next(context);
}
catch (Exception ex)
{
context.Request.Path = "/error/500";
await next.Invoke(context);
}
}
}