大家好,我使用过 [Authorize],但是当重定向到登录视图时,我可以登录任何用户名或密码,那么问题是什么,并且还要检查用户是否登录?
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(Panel model, string Username, string Password)
{
if (ModelState.IsValid)
{
if (model.Username == Username && model.Password == Password)
{
FormsAuthentication.SetAuthCookie(model.Username, false);
return RedirectToAction("Index", "Test");
}
else
{
ModelState.AddModelError("", "Wrong username or password");
}
}
return View();
}
[Authorize]
public ActionResult Index()
{
return View();
}