问题
I'm struggeling with setting up default membership. I can register, but later I'm unable to login to my app. The Membership.ValidateUser always returns false.
This is the configuration I'm using:
<connectionStrings>
<clear />
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:s09.winhost.com;Initial Catalog=*****;User ID=******;Password=**********;Integrated Security=False;" />
</connectionStrings>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<clear/>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider" hashAlgorithmType="SHA1">
<providers>
<clear/>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/goaly" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<clear/>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<clear/>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
<machineKey validationKey="2CE9C29E0CA905FA4CB11E7A20158566A1C7B0CFD9B94528B6758FB1B1588E2928B70F7D1EC2174CB1CB2C6AAB03F2D3848B502AEB46C60B7370A032FFDA716C" decryptionKey="6B0F32F19532E948C4431B9437A12F32BE56706DB3483205706ECCF2BDA7C167" validation="SHA1" decryption="AES" />
I've seen several questions Why does Membership.ValidateUser() always return false? but I've tried added both a machine key and a setting the hashalgoritm.
I can see that a new record is created in dbo.Memberships table and in the dbo.User table when I register a new user, but login in is not possible.
One possible problem could be that a view or stored procedure is missing, I've not created any of those, just assuming they would be created correctly (the User, UsersInRolesm Roles, Profiles, Memberships tables was created automagically)
Thanks for any help
Larsi
回答1:
Arghhhh!!!
I found out why I was not able to log in.
In my accountcontroller (created by mvc 4 template) the line
Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);
was changed to
Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: false, providerUserKey: null, status: out createStatus);
When I grab a the latest bits it's set to true. No idea of why it was set to false.
Maybe the template has changed, or maybe the IsApproved functionality has changed. Anyway it no works fine.
Larsi
回答2:
Other possible causes:
1: Password incorrect
2: User is Locked
3: User is not Approved
4: somethin else???? and needs more investigation. i.e. was it working before and stopped working? did you make any other changes like passwordFormat or something to your memberhsip provider....and so on.
Source: http://forums.asp.net/t/1392208.aspx
来源:https://stackoverflow.com/questions/11811978/membership-validateuser-always-returns-false