英文:
How to logout OAuth 2.0 when stop the program using Microsoft.AspNetCore.Authentication.Google
问题
我使用 .net core 7 和 Microsoft.AspNetCore.Authentication.Google 来进行谷歌身份验证。一切都正常,但当我停止程序时,它不会自动注销。它会在浏览器上保存 cookies。<br/>如果我想要注销,我在控制器中调用 await HttpContext.SignOutAsync();
。<br/>我如何在停止程序时自动调用 await HttpContext.SignOutAsync();
?
英文:
I use .net core 7 and Microsoft.AspNetCore.Authentication.Google to use google authentication. It is ok but when I stop the program, it is not auto logout. It saves cookies on the browser. <br/>If I want logout, I call await HttpContext.SignOutAsync();
in the controller. <br/>How can I auto call await HttpContext.SignOutAsync();
when I stop the program?
答案1
得分: 0
首先,我创建了一个静态变量public static int isNew = 0;
。
然后,我将该代码放到HomeController的Index操作中。
if (TimeLife.isNew == 0)
{
await HttpContext.SignOutAsync();
TimeLife.isNew = 1;
}
它运行良好。
应用程序将在第一次登录时自动注销。
英文:
A trick
First, I create a static variable public static int isNew = 0;
</br>
Then, I put that code to Index action in HomeController <br>
if (TimeLife.isNew == 0)
{
await HttpContext.SignOutAsync();
TimeLife.isNew = 1;
}
<br>It work good.
<br> The application will auto logout in the first login
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论