Ich habe HomeController
mit AuthorizeAttribute
dekoriert erstellt, und auch AccountController
erstellt, aber es ist nicht auf die Login()
Wirkung von AccountController
umgeleitet wird.Mvc Autorisieren Attribut funktioniert nicht
Heimsteuerung:
[Authorize]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
Konto Controller:
public class AccountController : Controller
{
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(LogOnCustom log)
{
if(ModelState.IsValid)
{
if(Membership.ValidateUser(log.UserName,log.Password))
{
FormsAuthentication.RedirectFromLoginPage(log.UserName, log.Isremeber);
}
else
{
ModelState.AddModelError("", "logOn error");
}
}
return View(log);
}
}
web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" >
</forms>
</authentication>
Bitte beachten Sie, dass das Model-View-Controller-Tag für Fragen zum Muster dient. Es gibt ein bestimmtes Tag für die ASP.NET-MVC-Implementierung. –
@StephenMuecke danke – anitha