![](/img/trans.png)
[英]How can I get 'minimum password age' of user in active directory using asp.net?
[英]In ASP.NET Core, how to know the user meets the minimum age?
我正在關注有關 asp.net 核心授權的本教程: https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-3.0
該示例創建了一個 MinimumAgeRequirement 並將其年齡設置為 21。問題是我在代碼中找不到將用戶年齡設置為 21 的位置。所以似乎永遠不會滿足要求?
auth 聲明強化了最低要求,其中登錄用戶上下文用於檢查出生日期並與最低年齡要求進行比較。 這是代碼片段。
var dateOfBirth = Convert.ToDateTime(
context.User.FindFirst(c => c.Type == ClaimTypes.DateOfBirth &&
c.Issuer == "http://contoso.com").Value);
為用戶添加聲明:
await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.DateOfBirth, myDateOfBirth));
您可以在 HomeController 上找到包含 AgeRequirement、Handler、Claim 和 Authorize 的完整項目。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.