Search code examples
asp.netasp.net-membership

ASP.NET membership - login fails


I'm writing a web application, using ASP.NET MVC4 and SQL Azure. I use forms authentication and the Membership library. In production, the website runs from a web role service in Azure.

When I register a new user from my dev environment, the login from production environment fails, and vice versa. Login with some user & password that I created in the same environment succeeds. I know it sounds like different configurations in dev and production, however I verified that they both work with the same DB, and also verified that user details from both sources (dev and production) are written to the same tables ('users' and 'memberships').

This is the CreateUser command:

MembershipUser user = Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus);

And this is the login command that fails:

if (Membership.ValidateUser(model.Email, model.Password))

Thanks.


Solution

  • Most likely, dev and production have different MachineKey's. The MachineKey is used to generate the hash, so a different key means passwords don't work.

    Set the MachineKey in the web.config explicitly in both.

    http://msdn.microsoft.com/en-us/library/ff649308.aspx#paght000007_webfarmdeploymentconsiderations