在.NET Core中,HttpContext.SignOutAsync()和ControllerBase.SignOut()有什么区别?

时间:2019-12-05 01:22:45

标签: c# asp.net-core asp.net-core-mvc asp.net-core-2.2 ws-federation

我目前正在 .NET Core 2.2 中为我们的WsFederation实现注销方法。我发现了这两种方法:

  1. ControllerBase.SignOut方法
  2. AuthenticationHttpContextExtensions.SignOutAsync方法

我找到了两个答案:

  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

我还查看了Microsoft文档:

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

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

仍然没有明确的答案。

谁能告诉我有什么区别?以及应该使用哪一个从我在Startup.cs中建立的中间件中注销认证/ WsFederation。

谢谢!

T

1 个答案:

答案 0 :(得分:2)

查看SignoutResult的{​​{3}}(ControllerBase.Signout返回新的SignoutResult),ExecuteResultAsync在{{1}上调用SignOutAsync }。唯一的不同可能是在HttpContext上调用它会导致将正确的响应发送到客户端。