简体   繁体   English

SimpleMembershipProvider无法在Azure上运行

[英]SimpleMembershipProvider not working on Azure

I'm hosting a simple ASP.NET MVC5 Web Application on Azure and I'm using SimpleMembershipProvider to hand authentication. 我在Azure上托管了一个简单的ASP.NET MVC5 Web应用程序,并且正在使用SimpleMembershipProvider进行手动身份验证。

Everything works fine on my local machine, but when I try to log in on the Azure application, WebSecurity.Login always returns false. 在本地计算机上一切正常,但是当我尝试登录Azure应用程序时,WebSecurity.Login始终返回false。 No exceptions happen, and all of the UserProfiles appear in the database. 没有异常发生,并且所有UserProfiles都出现在数据库中。 I tried debugging my login method, but WebSecurity.Login is a bit of a black box, so I'm not sure why it's returning false. 我尝试调试登录方法,但是WebSecurity.Login有点黑框,因此我不确定为什么它返回false。

 public ActionResult Login(Login loginData, string ReturnUrl)
    {       
        if (ModelState.IsValid)
        {
            if (WebSecurity.Login(loginData.Username, loginData.Password))
            {
                if (ReturnUrl != null)
                {
                    return Redirect(ReturnUrl);
                }
                return RedirectToAction("Index", "Home");
            }
        }
        ModelState.AddModelError("", "Sorry the username or password is incorrect");
        return View(loginData);
    }

After some research I've gotten it working. 经过研究后,我开始使用它。 It seems that the password hash generated when I seeded the database from my development machine was different than the one calculated by the server. 看来,当我从开发机中为数据库注入种子时生成的密码哈希与服务器计算的密码哈希不同。 I'm not sure why that is, but the login function started working correctly once I called the CreateUser function on application start on the server, rather than from Update-Database on my development machine. 我不确定为什么会这样,但是登录功能一旦在服务器上启动的应用程序上调用了CreateUser函数(而不是从开发计算机上的Update-Database调用)后便开始正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM