我正在學習Asp.net核心MVC 2.0,無法弄清楚如何訪問登錄用戶的屬性。如何訪問登錄用戶的屬性?
爲了便於說明,我們使用由Visual Studio Community生成的默認模板Asp.net Core MVC 2.0,並選擇Individual User Account
。
該模板爲我們提供了一個從IdentityUser
繼承的空的ApplicationUser
。同樣,爲了簡單起見,我僅向ApplicationUser
添加了一個屬性Point
,如下所示。
public class ApplicationUser : IdentityUser
{
public int Point { get; set; }
}
的Point
將跟蹤次登錄的用戶訪問「/首頁/索引」的數量。這對於簡單來說是一個微不足道的場景。
問題
現在,我不知道如何訪問屬性Point
和每一個他/她訪問/Home/Index
時間增加了。
我試圖通過User.Identity
訪問屬性Point
顯示如下,但失敗。
你能告訴我正確的方法是什麼?
你嘗試用(ApplicationUSer)User.Identity鑄造? –