-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Returning TypedResult.Redirect become EmptyHttpResult #56714
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
Comments
Workaround (No idea why i need to do this work around, but it works)
|
You're returning a |
Sorry, first sample will compile error, wrong copy paste What make it work in workaround is response redirect, without that line, its not redirecting |
Can you please share a minimal repro, because trying to reproduce this shows it working as expected.
|
I will try, im on holiday at this moment, i have no access to laptop for a week something |
@BrennanConroy for some reason, that endpoint always running in this delegate, do you maybe know why the filter running on that delegate? |
Again, please share a minimal repro, just showing screenshots of our code isn't helpful. |
Took a while to create the repro but here you go |
Simplified repro: var g = app.MapGroup("/test").AddEndpointFilter(async (c, next) =>
{
var res = await next(c);
return res;
});
g.MapGet("/red", H.Redirect);
public static class H
{
public static async Task<RedirectHttpResult> Redirect(HttpContext h)
{
await Task.Delay(100);
return TypedResults.Redirect("/"); //This redirect is the cause of EmptyHttpResult
}
} This is the same as #44316 where we wrote an analyzer that should be warning you about this pattern TLDR; if you want the |
Existing issue 2 years ago PR that fixed it PR that revert the fix Another issue that discuss the revert The reason to revert the change is to make it "reflection free" Tbh, i do not get the "reflection free" in minimal api since AddEndpointFilterFactory use reflection, does this mean using AddEndpointFilterFactory is discouraged? (Tried to ask this in discussion but no one answer) if yes what is the alternative solution? But |
"reflection free" is incorrect wording. They meant non-trim safe reflection which
No, the first request is probably slow because all the generated code is created on first request. |
Thank you for your reply, i think there is not much we can do in this issue... I will see if I can create endpoint directly with RequestDelegate as its fast start up, the only problem is that all of my filter basically broken with RequestDelegate... |
Is there an existing issue for this?
Describe the bug
I have simple minimal api that signout and doing redirect, it always return EmptyHttpResult for no reason
It is funny because i have login endpoint with minimal api that do RedirectResult but it works
Expected Behavior
returning TypedResult.Redirect should just work
Steps To Reproduce
internal static async Task Post(HttpContext httpContext)
{
if (httpContext.User.Identity.IsAuthenticated)
{
await httpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}
return TypedResults.Redirect("/");
}
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: