【发布时间】:2015-05-07 21:22:40
【问题描述】:
我正在通过尝试将 .NET Web 应用程序转换为 ASP.NET MVC 来学习 ASP.NET MVC。 我有一个控制器和登录视图。 如果用户通过身份验证,我想重定向到默认视图。
这是文件夹结构:
Views
- Account
- Home
- Shared
Default.cshtml
这是控制器中的登录操作:
public ActionResult Login(LoginModel model)
{
if (ModelState.IsValid)
{
bool authenticated = Security.AuthenticateLANUser(model.UserName, model.Password);
if (!authenticated)
{
Session["authenticated"] = false;
System.Text.StringBuilder errorMsg = new System.Text.StringBuilder();
errorMsg.Append("Invalid Login/Password entered.");
errorMsg.Append("We were not able to authenticate you in in Active Directory based on the information entered, ");
errorMsg.Append("but we recorded your attempt for audit purposes.");
ModelState.AddModelError("", errorMsg.ToString());
return View(model);
}
else
{
return View("Views/Account/Default.cshtml");
}
}
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
用户已通过身份验证,我应该被重定向到默认视图,但它不会重定向。我做错了什么?
【问题讨论】:
-
您的代码中没有重定向。它必须是
return RedirectToAction("Default", "Account");假设你有一个AccountController和Default方法
标签: asp.net asp.net-mvc asp.net-mvc-4