我的 asp .net mvc3 应用程序有问题
当我创建一个新帐户时,我有一个登录操作方法和一个视图,例如“用户”,一切正常,用户已添加到 sql server DB,如您所见,它显示在“欢迎用户”上方:
但是当我使用这个用户登录时,它没有登录:用户永远不会被验证!
这是我的创建操作:
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(newRegisteration.Username, newRegisteration.Password, null, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(newRegisteration.Username, false /* createPersistentCookie */);
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
db.RegisterObj.Add(newRegisteration);
db.SaveChanges();
return RedirectToAction("Index", "Home");
//return RedirectToAction("Index");
}
else
{
return View(newRegisteration);
}
............. 登录操作如下:
public ActionResult LogOn(string returnUrl, RegisterationModel model)
{
Membership.CreateUser(model.Username, model.Password);
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.Username, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Username, true);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
我想添加打印屏幕,但我不能 bcz 我是新用户,任何人都可以帮助我,,,,