我目前正在开发一个用ASP.NET MVC编写的项目,我现在正在努力解决这个错误。以下是情景。
情景:此项目顺便使用 T4MVC插件
任何想法在这里发生了什么?
更新
登录代码。这是用于登录表单发布。它使用Index()操作方法重定向到/ Administration控制器。
public virtual ActionResult Index(LoginFormInput loginFormInput, string returnUrl)
{
if (!ModelState.IsValid)
{
return this.View();
}
if (!FormsAuthentication.Authenticate(loginFormInput.Username, loginFormInput.Password))
{
ModelState.AddModelError("login", BridgeDirect.Properties.Common.LoginFailure);
return this.View();
}
FormsAuthentication.SetAuthCookie(loginFormInput.Username, loginFormInput.RememberMe);
if (!string.IsNullOrEmpty(returnUrl))
{
return this.Redirect(returnUrl);
}
else
{
return this.RedirectToAction(MVC.Login.Index());
}
}
答案 0 :(得分:1)
在验证用户的控制器方法中 如果成功只返回RedirectToAction(“索引”,“控制器”)
答案 1 :(得分:1)
魔术发生在帐户控制器中(我猜您使用的是ASP.NET个人用户帐户)
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
// AFTER A SUCCESSFULL LOGIN THIS REDIRECTS THE USER TO THE
// PREVIOUS PAGE
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
答案 2 :(得分:0)
更改此
return this.RedirectToAction(MVC.Login.Index());
到此
return RedirectToAction("Index","TheIndexMethodController");
如果我猜测它将是一些HomeController,如下所示:
return RedirectToAction("Index","Home");