Nous essayons de faire un site Web qui a un écran de connexion. Mais nous avons un problème. Notre domaine est localhost/Login/Utilisateur. Mais si l'utilisateur entre localhost/Home/Index, il/elle peut accéder à notre site principal sans connexion. Nous avons donc écrit [Authorize] sur notre Index Controller. Mais je ne pouvais pas savoir ce que je devais utiliser. Dois-je utiliser AuthorizeAttribute dans notre projet?Authentification MVC dans le contrôleur
#Login Page
public class LoginController : Controller
{
//GET: Login
[IntranetAction]
public ActionResult Users()
{
return View();
}
public ActionResult Authentication(UserLoginInfo loginInfo)
{
bool isAuthenticated = new LdapServiceManager().isAuthenticated(loginInfo);
if (isAuthenticated)
{
//AUTHORIZED
Session["userName"] = loginInfo.username;
return Redirect("/Home/Index");
}
//WORNG PASSWORD, BACK TO LOGIN PAGE
TempData["message"] = "Yanlış kullanıcı adı ya da şifre";
return Redirect("/");
}
}
Index Page
[Authorize]
public ActionResult Index()
{
Session["ip"] = Request.UserHostAddress;
if (IsDbExists())
{
_contactList = new List<Contact>();
UpdateOperations();
return View(_contactList);
}
Response.Redirect("/Loading/LoadingScreen");
return null;
}
Comment puis-je accéder à l'index dans ma LoginController/fonction d'authentification