Answered by:
Call to WebSecurity.Login always returns false. Even though the database is open?

Question
-
User1080700311 posted
I created my own sql server tables to Authenticate against. I am using MVC 4. In the InitializeSimpleMembershipAttributes.cs file, I changed the InitializeDatabaseConnection statement to point to my own database, and tables.
WebSecurity.InitializeDatabaseConnection("CabelConnectionString", "ClubUsers", "UserID", "userName", autoCreateTables: false);
That code executes and opens my database. However, in my controller code when the code WebSecurity.Login is executed, it is not logging in successfully? Strange, because I can call other WebSecurity methods. This is proving to me that my database ClubUsers is indeed open and I can query it succesfully.
So why is my call to WebSecurity.Login failing? Below is my code in my AccountController.cs. I only get back a boolean value of false, so I am not able to identify the exact cause of failure.
1 bool testThis = WebSecurity.UserExists("Trandy"); // This line will return true when executed.
2 int theId = WebSecurity.GetUserId("Trandy"); // the user Id for Trandy is being returned and is valid// I hard coded the input parameters, just for testing the code.
3 bool isLogged = WebSecurity.Login("Trandy", "Sunday", persistCookie: model.RememberMe); // Is returning false?if(isLogged == true)
{
//code execution Never gets here ? Not returning a true value from login attempt
}else
{
// Else block is always executed indicating a false value is being returned.
}Tuesday, January 29, 2013 10:55 PM
Answers
-
User1080700311 posted
Hi. The reason for the error, is that the webpages_Membership table did not exists. This table is queried the the username when you try to Login. Their is a seperate WebSecurity command named websecurity.createaccount for creating the webpages_Membership table.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 31, 2013 9:33 PM
All replies
-
User1957004874 posted
bool isLogged = WebSecurity.Login("Trandy", "Sunday", persistCookie: model.RememberMe); // Is returning false?If everything is right, then I guess you have the wrong password.
Wednesday, January 30, 2013 9:11 PM -
User1080700311 posted
Hi CPrakeash, I am fairly certain I triple checked that. I will check it again in the morning. If you right, I will turn purple.
Wednesday, January 30, 2013 11:42 PM -
User1080700311 posted
Hi. The reason for the error, is that the webpages_Membership table did not exists. This table is queried the the username when you try to Login. Their is a seperate WebSecurity command named websecurity.createaccount for creating the webpages_Membership table.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, January 31, 2013 9:33 PM