我想读取MVC PasswordOptions
中配置的Identity .我的配置如下:Startup.cs
Controller
PasswordOptions
services.AddIdentity(config => { config.Password.RequireDigit = true; config.Password.RequiredLength = 8; config.Password.RequireNonAlphanumeric = true; });
然后RequireDigit
,我如何读取应用程序中的某个或其他位置的PasswordLength
,和RequireNonAlphanumeric
属性Controller
?
使用ASP.NET Core 1.0.1.
只需将IOptions
接口注入任何类或控制器的构造函数,如下所示:
public class MyController : Controller { private readonly IOptions_identityOptions; public MyContoller(IOptions identityOptions) { _identityOptions=identityOptions?.Value ?? new IdentityOptions(); } public MyAction() { var length=_identityOptions.Value.Password.RequiredLength; } }