これは MVC 4 で書かれたイントラネット アプリケーションで、ユーザー ログインが必要です。ユーザーが入力したユーザー名からドメインを削除するのに最適な場所はどこですか? ( 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
...