--- lang: ja-jp breaks: true --- # ASP.NET Core Googleログイン中にキャンセルボタンを押すとエラーが発生する。 2024-09-18  ## 調査 > Exception on cancelled external login > https://stackoverflow.com/questions/51455421/exception-on-cancelled-external-login ## `builder.Services` `AddGoogle` で、`Events.OnRemoteFailure` をハンドルすると正常に動作する。 * Program.cs ```csharp= builder.Services .AddAuthentication(options => { ・・・ }) .AddCookie( CookieAuthenticationDefaults.AuthenticationScheme, option => { ・・・ }) .AddCookie(IdentityConstants.ExternalScheme) .AddGoogle(options => { ・・・ options.Events.OnRemoteFailure = (context) => { if (context.Request.Query["error"] .Where(n => n == "access_denied") .Any() == true ) { // Google 認証に失敗した場合、ログインページにリダイレクトする。 // Googleログイン中にキャンセルを押すと、ここに来る。 context.Response.Redirect("/Account/GoogleLogin"); context.HandleResponse(); } return Task.CompletedTask; }; }); ``` ###### tags: `ASP.NET Core` `Identity` `Blazor` `Google` `ログイン`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up