开发者

ASP Membership problem

开发者 https://www.devze.com 2023-03-28 11:50 出处:网络
I am doing examples from APRESS ASP MVC Book. And I get to membership. I follow example from the book, but I want to change to not have credentials in web.config. But I always get \'false\' from \'For

I am doing examples from APRESS ASP MVC Book. And I get to membership. I follow example from the book, but I want to change to not have credentials in web.config. But I always get 'false' from 'FormsAuthentication.Authenticate()'

 <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <membership defaultProvider="MyMembershipProvider">
      <providers>
        <add name="MyMembershipProvider"
        connectionStringName="myConnectionString"
        applicationName="MyMembership"
    开发者_运维百科    enablePasswordRetrieval="false"
        enablePasswordReset="true"
        requiresQuestionAndAnswer="false"
        requiresUniqueEmail="true"
        passwordFormat="Hashed"
        type="VVU.CityLink.WebUI.Infrastructure.Concrete.FormsAuthProvider"
        minRequiredNonalphanumericCharacters="0"/>
      </providers>
    </membership>

    <authorization>
      <deny users="?"></deny>
    </authorization>

[HttpPost]
        public ActionResult LogOn(LogOnViewModel model, string returnUrl)
        { 

            if(ModelState.IsValid)
            {
                if (authProvider.Authenticate(model.Username, model.Password))
                {
                    return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
                }
                else
                {
                    ModelState.AddModelError("", "Incorrect username or password");
                    return View();
                }
            }
            else
            {
                return View();    
            }

        }

public class FormsAuthProvider : IAuthProvider
    {
        public bool Authenticate(string username, string password)
        {
            bool result = FormsAuthentication.Authenticate(username, password);

            if(result)
            {
                FormsAuthentication.SetAuthCookie(username, false);
            }
            return result;
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消