
我在頁面的 cshtml 中有這個 if 陳述句。出于某種原因,它一直告訴我 User.Identity.IsAuthenticated 是對可能的空參考的取消參考,并且當程式啟動時它不考慮該陳述句。如何解決?
這是在實施您的解決方案之后
補充:錯誤發生在post上
uj5u.com熱心網友回復:
利用:
@if (User.Identity?.IsAuthenticated == true)
{
}
檢查Nullable 背景關系和Null 條件運算子。
uj5u.com熱心網友回復:
Dereference of possible null reference使用時我也得到User.Identity.IsAuthenticated,但沒有被忽略,它有效,你驗證了這個頁面嗎?
除此之外,也許您可??以改用Request.IsAuthenticated。
uj5u.com熱心網友回復:
我修復了錯誤。在回傳頁面示例之前,我在 onPost 方法中呼叫了 onGet 方法:
public void onGet()
{
//code
}
public void onPost()
{
//code
onGet();
return Page();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/530290.html
上一篇:身份驗證失敗,因為遠程方在呼叫3rd方API時發送了TLS警報
下一篇:嘗試激活“x.Areas.xController”時無法決議“Microsoft.AspNetCore.Identity.UserManager`1[x.AppUser]”型別的服務
