Search code examples
c#asp.net-coreasp.net-core-mvcasp.net-core-2.2ws-federation

In .NET Core, What are the differences between HttpContext.SignOutAsync() and ControllerBase.SignOut()?


I am currently implementing a signout method for our WsFederation in .NET Core 2.2. And I found these two methods:

  1. ControllerBase.SignOut Method
  2. AuthenticationHttpContextExtensions.SignOutAsync Method

I found these two answers:

  1. SignOut (LogOut) Error in AspNetCore 2.1 with WsFederation

  2. ASP.NET Core Identity 2.0 SignoutAsync is not logging out user if the user signed in with Google

I also checked out the Microsoft documentation:

  1. https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.signout?view=aspnetcore-2.2#Microsoft_AspNetCore_Mvc_ControllerBase_SignOut_System_String___

  2. https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.authenticationhttpcontextextensions.signoutasync?view=aspnetcore-2.2#Microsoft_AspNetCore_Authentication_AuthenticationHttpContextExtensions_SignOutAsync_Microsoft_AspNetCore_Http_HttpContext_

Still don't have a clear answer.

Can anyone tell me what are the differences? and Which one I should use for signing out the authentication/WsFederation from the middleware I established in Startup.cs.

Thanks in advance!

T


Solution

  • Looking at the source for SignoutResult (ControllerBase.Signout returns a new SignoutResult), ExecuteResultAsync calls SignOutAsync on the HttpContext. The only difference might be that calling it on the ControllerBase results in a proper response being sent to the client.