Closed gthvidsten closed 10 months ago
Thank you for contacting us. It looks like you are using the HttpContext after it is disposed. Can you get a full stack trace for the exception?
Here's the full stack trace:
at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.ThrowContextDisposed()
at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.Fetch[TFeature,TState](TFeature& cached, TState state, Func`2 factory)
at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.Fetch[TFeature](TFeature& cached, Func`2 factory)
at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Scheme()
at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.BuildRedirectUri(String targetPath)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.BuildRedirectUriIfRelative(String uri)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.<SignOutAsync>d__15.MoveNext()
at Microsoft.AspNetCore.Authentication.AuthenticationService.<SignOutAsync>d__18.MoveNext()
at My.Pages.LogoutModel.<OnGet>d__0.MoveNext() in C:\MyProject\Pages\Logout.cshtml.cs:line 13
For completion, here's my Logout.cshtml:
@page
@model MyProject.Pages.LogoutModel
And the model:
public class LogoutModel : PageModel
{
public async void OnGet()
{
await HttpContext.SignOutAsync("oidc", new AuthenticationProperties { RedirectUri = Url.Content("~/") });
await HttpContext.SignOutAsync("MyScheme");
}
}
And to reiterate: If I log in and call Logout.cshtml everything works. If I log in, restart the application, then call Logout.cshtml, both SignOutAsync()
calls fails with the exception above.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Can you try to fix the signature of your OnGet
method to return Task
, as follows:
public async Task OnGet()
Hi @gthvidsten. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Can you try to fix the signature of your
OnGet
method to returnTask
, as follows:public async Task OnGet()
That did the trick. The exception disappeared.
I see you already mentioned this in the Analyzers issue and I agree that this could be caught in an analyzer.
I was under the impression that async void
could be used for events, and OnGet()
sounds like an event where you would expect async void
to work, so having an analyzer tell you otherwise would be nice.
Thanks for confirming, @gthvidsten. That's great. Closing this as the analyzer will be the only actionable thing for us here and that's already tracked in a separate issue.
Is there an existing issue for this?
Describe the bug
Starting a Blazor Server app, logging in using
await HttpContext.ChallengeAsync("oidc");
, stopping the app, starting the app again, then callingawait HttpContext.SignOutAsync("oidc")
causes anObjectDisposedException
with the messageIFeatureCollection has been disposed
.Expected Behavior
Expected
await HttpContext.SignOutAsync("oidc")
to work without any exceptions.Steps To Reproduce
I've set up a .NET7 Blazor Server, the set up OIDC using the following code:
I have a
login.cshtml
which only callsawait HttpContext.ChallengeAsync("oidc");
, and I have alogout.cshtml
which calls bothawait HttpContext.SignOutAsync("oidc");
andawait HttpContext.SignOutAsync("MyScheme")
(in this order).Exceptions (if any)
ObjectDisposedException
when callingSignOutAsync("oidc")
saying:.NET Version
7.0.402
Anything else?
ASP.NET Core: 7.0.12 Microsoft.AspNetCore.Authentication.OpenIdConnect: 7.0.12 Visual Studio 2022 Professional: 17.7.5
dotnet --info
: