kin*_*ohm 3 asp.net-mvc asp.net-identity asp.net-core-mvc
我想读取MVC PasswordOptions中配置的Identity .我的配置如下:Startup.csControllerPasswordOptions
services.AddIdentity<ApplicationUser, IdentityRole>(config => {
config.Password.RequireDigit = true;
config.Password.RequiredLength = 8;
config.Password.RequireNonAlphanumeric = true;
});
Run Code Online (Sandbox Code Playgroud)
然后RequireDigit,我如何读取应用程序中的某个或其他位置的PasswordLength,和RequireNonAlphanumeric属性Controller?
使用ASP.NET Core 1.0.1.
只需将IOptions<IdentityOptions>接口注入任何类或控制器的构造函数,如下所示:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
654 次 |
| 最近记录: |