我切换到SimpleMembershipProvider
ASP.NET MVC 4 应用程序。其他一切都很好,但是有这个问题......
当我尝试这段代码时:
var password = Membership.GeneratePassword(Membership.MinRequiredPasswordLength, 0);
MinRequiredPasswordLength
始终为 0。Web.config
未读取成员资格提供程序部分中定义的设置。
这是成员资格默认提供程序Web.config
部分:
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="DefaultConnection"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/Acad" />
</providers>
</membership>
这是我得到的调试信息:
有什么提示吗?
是否SimpleMembershipProvider
如此简单以至于它甚至不使用 Web.config 部分?
暂时解决
为了克服SimpleMembershipProvider
当前的限制,我使用这段代码来获取定义的值Web.config
:
MembershipSection membershipSection = (MembershipSection)WebConfigurationManager.GetSection("system.web/membership");
var defaultProvider = membershipSection.DefaultProvider;
ProviderSettings providerSettings = membershipSection.Providers[defaultProvider];
var minRequiredPasswordLength = int.Parse(providerSettings.Parameters["minRequiredPasswordLength"]);