簡體   English   中英

嘗試注銷時未調用 OnPost

[英]OnPost not called when trying to log out

我有一個 Blazor 應用程序,我成功地通過 GET 請求注銷。

https://localhost:44300/Identity/Account/LogOut

public class LogoutModel : PageModel
{
    public async Task<IActionResult> OnGetAsync()
    {
        await HttpContext.SignOutAsync();
        return Redirect("/Identity/Account/Unauthorized");
    }
}

然而,有充分的理由這個 GET 應該是一個 POST。
所以我將代碼更改為:

public class LogoutModel : PageModel
{
    public async Task<IActionResult> OnPostAsync()
    {
        await HttpContext.SignOutAsync();
        return Redirect("/Identity/Account/Unauthorized");
    }
}

OnPostAsync()方法沒有被調用,當我調用以下 fetch 方法時我得到 400 響應。

await fetch('https://localhost:44300/Identity/Account/LogOut', { method: 'POST', headers: { 'Content-type': 'application/json; charset=UTF-8' }})

我需要做些什么來確保它被調用?

請求驗證失敗,因此我通過將IgnoreAntiforgeryToken 屬性添加到 LogoutModel class 來禁用它:

[IgnoreAntiforgeryToken(Order = 1001)]
public class LogoutModel : PageModel
{
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM