这是我的控制器。它不适合登录的用户阻止访问登录页面。请帮助我。我已经使用了request.Is Authenicated和User.Identity方法在我的控制器阻止登录的用户访问登录页面asp.net mvc应用程序
[HttpPost]
[AllowAnonymous]
public ActionResult Login(LoginViewModel model, string returnUrl)
{
if (Request.IsAuthenticated)
{
return RedirectToAction("Main","Home");
}
else if (!this.ModelState.IsValid)
{
return this.View(model);
}
else if (Membership.ValidateUser(model.Username, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return this.Redirect(returnUrl);
}
return this.RedirectToAction("Main", "Home");
}
this.ModelState.AddModelError(string.Empty,"Invalid Credentials.");
this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
return this.View(model);
}