【发布时间】:2012-02-14 17:10:19
【问题描述】:
使用 asp.net MVC 3 时,从模板安装的默认网站具有 AccountModel。其中,密码属性有DataAnnotations,这里设置了StringLength 的MinimumLength。
但是,在 .NET 框架成员资格提供程序中,您可以通过 web.config 文件设置 minRequiredPasswordLength。
现在如果您将 minRequiredPasswordLength 设置为 6,但将 AccountModel.password MinimumLength 设置为 1,那么如果您的密码长度只有 1 个字符,您将无法注册。反之亦然,minRequiredPasswordLength 为 1 而MinimumLength 为 6 将不允许注册。
所以对我来说这有点倒退。如果应用程序的安装不需要更长的密码长度,那么您必须在模型中进行更改。
DataAnnotations 必须是我所读到的常量值,那么有没有办法将这两者联系起来?理想情况下,我只需要更改 web.config 中的值,而不必担心重建项目。
编辑
在查看更多 Pre MVC 3 工具更新后,我注意到项目模板实际上包含一个 DataAnnotation,它将 Membership minRequiredPasswordLength 属性从 web.config 链接到 AccountModel
在这里写博客:http://timjames.me/mvc-3-password-length-dataannotation
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 asp.net-membership data-annotations