在查看登录时,请使用以下方式登录:
用户: admin 密码: xxx
我可以正常登录。
当您尝试使用以下方式时:
用户: tavaresdemelo.adv.br 密码: xx
会显示错误消息:
未找到视图“tavaresdemelo.adv.br”或其主控件,或者视图引擎不支持搜索的位置。已搜索以下位置:~/Views/account/tavaresdemelo.adv.br.aspx ~/Views/account/tavaresdemelo.adv.br.ascx ~/Views/Shared/tavaresdemelo.adv.br.aspx ~/Views/Shared/tavaresdemelo.adv.br.ascx ~/Views/account/tavaresdemelo.adv.br.cshtml ~/Views/account/tavaresdemelo.adv.br.vbhtml ~/Views/Shared/tavaresdemelo.adv.br.cshtml ~/Views/Shared/tavaresdemelo.adv.br.vbhtml
账户控制器
public ActionResult LogOn()
{
return View();
}
[HttpPost]
public ActionResult LogOn(string userName, string password, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(userName, password))
{
FormsAuthentication.SetAuthCookie(userName, false);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
return Redirect(returnUrl);
return RedirectToAction("Index", "Home");
}
ModelState.AddModelError("", "Usuário ou senha estão inválidos");
}
// If we got this far, something failed, redisplay form
return View(userName);
}
public ActionResult LogOff()
{
FormsAuthentication.SignOut();
return RedirectToAction("Index", "Home");
}
查看登录记录
@model string
@{
ViewBag.Title = "Login";
}
<div id="login">
<h2>@ViewBag.Title</h2>
@Html.ValidationSummary(true, "Erro ao tentar efetuar o login.")
@using (Html.BeginForm())
{
<fieldset class="login">
<legend>Entre com seu usuário e senha</legend>
<div class="inline">
@Html.Label("userName", "Usuário: ")
@Html.TextBox("userName", Html.Encode(Model))
@Html.ValidationMessage("userName")
</div>
<div class="inline">
@Html.Label("password", "Senha: ")
@Html.Password("password")
@Html.ValidationMessage("password")
</div>
<div class="form-buttons">
<input type="submit" class="button" value="Login" title="Login" />
</div>
</fieldset>
}
</div>