We are trying to do some website which has login screen. But we have a problem. Our domain is localhost/Login/User. But if user enters localhost/Home/Index, he/she can reach our main site without login. So we wrote [Authorize] to our Index Controller. But I couldn't find out what I must use. Am I have to use AuthorizeAttribute in our project?
#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;
}
How can I access index in my LoginController/Authentication function