【发布时间】:2012-11-02 16:23:16
【问题描述】:
这是一个用 MVC 4 编写的需要用户登录的 Intranet 应用程序。从用户输入的用户名中删除域的最佳位置在哪里? (Username.Name.Split('\')[1];)。这是在用户输入域的情况下。
查看:
@Html.ValidationSummary(true, "Login failed.")
@using (Html.BeginForm())
{
<div style="width: 400px">
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.Username)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Username)
@Html.ValidationMessageFor(m => m.Username)
</div>
...
登录模式:
[Required]
[Display(Name = "Username")]
public string Username { get; set; }
....
控制器:
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.Username, model.Password))
{
//set authentication cookie
...
【问题讨论】:
标签: asp.net-mvc-4 asp.net-authentication