gpt4 book ai didi

asp.net-mvc - 如何在 ASP.NET MVC Controller 中获取 Identity PasswordOptions

转载 作者:行者123 更新时间:2023-12-04 17:18:15 27 4
gpt4 key购买 nike

我想阅读身份PasswordOptions Startup.cs 中配置的来自 MVC Controller .我的 PasswordOptions配置如下:

services.AddIdentity<ApplicationUser, IdentityRole>(config => {
config.Password.RequireDigit = true;
config.Password.RequiredLength = 8;
config.Password.RequireNonAlphanumeric = true;
});

那么我该如何阅读 RequireDigit , PasswordLength , 和 RequireNonAlphanumeric Controller 中的属性或应用程序的其他地方?

使用 ASP.NET Core 1.0.1。

最佳答案

只需注入(inject) IOptions<IdentityOptions>任何类或 Controller 的构造函数的接口(interface),如下所示:

 public class MyController : Controller
{
private readonly IOptions<IdentityOptions> _identityOptions;
public MyContoller(IOptions<IdentityOptions> identityOptions)
{
_identityOptions=identityOptions?.Value ?? new IdentityOptions();
}

public MyAction()
{
var length=_identityOptions.Value.Password.RequiredLength;
}
}

关于asp.net-mvc - 如何在 ASP.NET MVC Controller 中获取 Identity PasswordOptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41746369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com