我在ASP.NET MVC 4应用程序中切换到
SimpleMembershipProvider
.其他一切都很好但是有这个问题……
当我尝试这段代码时:
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当前限制,我使用this code来获取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"]);
解决方法
I switched to SimpleMembershipProvider in an ASP.NET MVC 4 app.
嗯,从您在web.config中显示的相关部分来看,这似乎根本就不是这样.您正在使用AspNetsqlMembershipProvider.
如果要切换到SimpleMembershipProvider,请确保已正确配置它:
<membership defaultProvider="SimpleMembershipProvider"> <providers> <clear/> <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider,WebMatrix.WebData" /> </providers> </membership>
这就是说SimpleMembershipProvider不支持通过web.config设置这些属性.它甚至没有使用它.如果您想要这样的功能,您必须自己实现它.