ASP.NET Membership.ValidateUser()始终返回“false”

这是我的web.config:

      

我甚至硬编码了用户名和密码:

  bool b = Membership.ValidateUser("user@mail.com", "pass123"); 

当我在数据库上执行选择时,我得到了正确的用户。

用户isAproved = true

用户isLockedout = 0

配置ASP.NET 2.0 Membership和其他Providers时,需要设置applicationName属性。 在你的web.config中,它丢失了:

       

你可以尝试在这里获得价值

 public bool Login(string userName, string password) { var provider = Membership.Provider; string name = provider.ApplicationName; // Get the application name here return Membership.ValidateUser(userName, password); } 

或者打开ASPNETDB数据库中的aspnet_Usersaspnet_Applications表,并确定在开发过程中创建用户和其他数据时使用的应用程序名称(查看aspnet_Application表以解决此问题)。

然后在web.cofig中正确设置属性:

       

有关更多详细信息,请阅读Scott-Gu的博客中的这篇文章。

对于遇到此问题的其他人,还要确保在创建/保存用户密码时使用的项目中使用相同的计算机密钥:

  

更多信息: https : //msdn.microsoft.com/en-us/library/ff649308.aspx