第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何擴展User.Identity的可用屬性

如何擴展User.Identity的可用屬性

慕尼黑8549860 2019-07-23 18:59:53
如何擴展User.Identity的可用屬性我正在使用MVC5 Identity 2.0登錄我的網(wǎng)站,其中身份驗證詳細(xì)信息存儲在SQL數(shù)據(jù)庫中。Asp.net Identity已經(jīng)以標(biāo)準(zhǔn)方式實現(xiàn),可以在許多在線教程中找到。IdentityModels中的ApplicationUser類已擴展為包含一些自定義屬性,例如整數(shù)OrganizationId。我們的想法是,可以創(chuàng)建許多用戶并將其分配給公共組織以實現(xiàn)數(shù)據(jù)庫關(guān)系。public class ApplicationUser : IdentityUser     {         public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)         {             // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType             var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);             // Add custom user claims here             return userIdentity;         }         //Extended Properties         public DateTime? BirthDate { get; set; }         public long? OrganizationId { get; set; }         //Key Mappings         [ForeignKey("OrganizationId")]         public virtual Organization Organization { get; set; }     }如何從控制器中檢索當(dāng)前登錄用戶的OrganizationId屬性?一旦用戶登錄,這是否可通過方法獲得,或者每次執(zhí)行控制器方法時,我是否始終根據(jù)UserId從數(shù)據(jù)庫中檢索OrganizationId?在網(wǎng)上閱讀我看到我需要使用以下內(nèi)容來登錄UserId等。using Microsoft.AspNet.Identity;...User.Identity.GetUserId();但是,OrganizationId不是User.Identity中可用的屬性。我是否需要擴展User.Identity以包含OrganizationId屬性?如果是這樣,我該怎么做呢。我經(jīng)常需要OrganizationId的原因是許多表查詢依賴于OrganizationId來檢索與登錄用戶相關(guān)聯(lián)的與組織相關(guān)的數(shù)據(jù)。
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 1620 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號