Asp.net MVC with SimpleMembershipProvider

48 Views Asked by At

I'm developing a web site using ASP.NET MVC. For membership, I'm using SimpleMembershipProvider. So, here is a part of my web.config:

This is on my Global.asax, in the Application_Start:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "UserID", "UserName", autoCreateTables: true);

Well, my problem is in the LogIn. Apparently, when I use WebSecurity.Login(username, password) it works. I assumed that because when putting it in an IF statement, returns true. But, when I use WebSecurity.IsAuthenticated.. it ALWAYS return FALSE. This is my LogIn controller:

public ActionResult ToLogIn([Bind(Include = "UserName, Password")] LogInModel _user)
    {
        if (ModelState.IsValid)
        {
            if (WebSecurity.Login(_user.UserName, _user.Password))
            {
                return RedirectToAction("Index", "Home")
            }

        }
        return View(_user);
    }

It works and redirect to the Index Home page, which use a layout where I check the WebSecurity.IsAuthenticated and, as I say before, it always return False.

0

There are 0 best solutions below