ASP会员问题

时间:2011-08-17 09:54:49

标签: c# asp.net sql-server asp.net-mvc asp.net-membership

我正在做APRESS ASP MVC Book的例子。我成为会员。我按照本书中的示例进行操作,但我想更改为web.config中没有凭据。但我总是从'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 个答案:

没有答案