<authentication mode="Forms">
<forms loginUrl="~/Home/Login" timeout="2880" />
</authentication> <authorization>
<allow users="admin"/>
<deny users="?"/>
</authorization> [Authorize]
public ActionResult Index()
{
return View();
} public ActionResult Login(string userName, string passWrod)
{
FormsAuthentication.SetAuthCookie(userName, true);
return RedirectToAction("Index");
} 为什么验证不通过的时候仍然跳转?但是我把 return RedirectToAction("Index"); 换成 return View();就不会有问题
我感觉是跳转方式的问题 验证代码应该没有什么问题
<forms loginUrl="~/Home/Login" timeout="2880" />
</authentication> <authorization>
<allow users="admin"/>
<deny users="?"/>
</authorization> [Authorize]
public ActionResult Index()
{
return View();
} public ActionResult Login(string userName, string passWrod)
{
FormsAuthentication.SetAuthCookie(userName, true);
return RedirectToAction("Index");
} 为什么验证不通过的时候仍然跳转?但是我把 return RedirectToAction("Index"); 换成 return View();就不会有问题
我感觉是跳转方式的问题 验证代码应该没有什么问题
{
string loginName = collection["LoginName"];
string password = Common.AES.Encode(collection["Password"].Replace("'", ""));
FormsAuthentication.SetAuthCookie(loginName, false);
if (!String.IsNullOrEmpty(ReturnUrl))
{
return Redirect(ReturnUrl);
}
else
{
return RedirectToAction("Index", "Admin");
}
}
这句代码的意思是验证成功后设置cookie,如果验证没通过就不应该调用这句。