Skip to main content
 首页 » 编程设计

c#之现在 identityconfig.cs 已被删除,在 ASP.NET 5.0 MVC Identity 中定义密码验证的正确位置在哪里

2024年02月05日15yxwkf

在之前的项目中,我在 App_start 文件夹的 identityconfig.cs 文件中定义了 .NET 身份的密码验证。以下将在 ApplicationUserManager 类下:

// Configure validation logic for passwords  
            manager.PasswordValidator = new PasswordValidator  
            {  
                RequiredLength = 6,  
                RequireNonLetterOrDigit = true,  
                RequireDigit = true,  
                RequireLowercase = true,  
                RequireUppercase = true,  
            };  

在最新版本的 .NET MVC 中,我使用的是 identityconfig.cs 并且 App_Start 已被删除。

关于现在可以在哪里设置这些变量,我一直无法找到明确的答案。希望有人能指出我正确的方向。

请您参考如下方法:

如果你在谈论 ASP.NET Core MVC 6 中的 Identity 3 您需要通过实现接口(interface) IPasswordValidator<T> 在对象中实现自定义逻辑.

然后在你的Startup.cs下IServiceProvider ConfigureServices(IServiceCollection services)方法 添加以下内容

services.AddScoped<IPasswordValidator<ApplicationUser>, YOUR_OBJECT>(); 

其中 ApplicationUser 是您的身份实现使用的用户对象

身份 3 已拆分为可扩展性接口(interface)