0
私のプログラムは前に働いていました。私はどのような変更を行ったのか分かりませんが、突然私のログインが変わってしまいました。管理者が承認したページにアクセスしようとするたびに、ログインしてもログインページにリダイレクトされ続けます。ここに私のコードです:MVC 4なぜ私のウェブサイトはアカウント/ログインにリダイレクトされますか?
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(AlvinCMSExtension.Models.LoginModel model, string returnUrl)
{
string redirectUrl = returnUrl;
string userName = model.UserName;
AlvinCMSExtension.Models.UserProfile user = dbAccount.UserProfiles.Where(m => m.Email.Equals(userName, StringComparison.CurrentCultureIgnoreCase)).SingleOrDefault();
if (user != null)
{
userName = user.UserName;
}
if (ModelState.IsValid && WebSecurity.Login(userName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToAction("LoginRedirectionControl", new { redirectUrl = redirectUrl });
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
public ActionResult LoginRedirectionControl(string redirectUrl)
{
string returnUrl = redirectUrl;
if (redirectUrl == null)
{
redirectUrl = User.IsInRole("Admin") ? "/Admin" : "/";
}
return RedirectToLocal(redirectUrl);
}
private ActionResult RedirectToLocal(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
return RedirectToAction("Home", "Page");
}
そして、私はこれにアクセスしようとした:
は[Authorize(Roles="Admin")]
public ActionResult Dashboard()
{
return View();
}
各ログインに成功した後、Redirect(returnUrl)
はにreturnurlに私を取ることはありませんが、代わりに、ページを再度ログインします。使用されるパラメータはhttp://localhost:5847/Account/Login?ReturnUrl=%2fAdmin%2fDashboard
です。私はコードをデバッグし、returnUrlは/Admin/Dashboard/
を保持しています。私は何が起こっているのか分からない。
これは私の愚かなことです。私は何が起こったのかわからないが、ええ、ユーザーインロールは削除されました。私はこれを考えなかった、私はそれがiisサーバーで何かだと思った。ありがとう –