美好的一天!登錄頁面登錄後再次出現MVC3
現在這是我的問題在我的項目。每次我登錄它總是在登錄頁面重定向。我試圖在我的控制器中放置一個斷點,它發生在首次登錄時,當我登錄並在我的控制器中單擊f10時,它會處於所有狀態。但是當我第二次登錄時,它會進入控制器並且該帳戶的角色是什麼。
我的代碼:
帳戶控制:
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
if (Roles.IsUserInRole("Employer"))
{
return RedirectToAction("CustomerIndex", "Customer");
}
else if (Roles.IsUserInRole("Worker"))
{
return RedirectToAction("WorkerIndex", "Worker");
}
else if (Roles.IsUserInRole("Administrator"))
{
return RedirectToAction("ClientIndex", "Client");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
LogOn.cshtml:
@using (Html.BeginForm())
{
<div style="width: 500px;">
<fieldset>
<legend>Account Information</legend>
<div class="editor-label" style="padding-top: 20px">
@Html.LabelFor(m => m.UserName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</div>
<div class="editor-label">
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe)
</div>
<p>
<input type="submit" value="Log On" class="styledButton" />
</p>
</fieldset>
</div>
}
謝謝。 :D
哦,geez !!!謝謝你幫助我! –
@VincentGumera,很高興能有幫助! :) –
豎起大拇指給你! :)) –