I've created my login using simple session element. I need a logout process as simple as i did. How can i create Log-out in harmony with my Log-in codes? Thanks in advance.
Here is my model below;
public class LoginModel
{
public string UserName { get; set; }
public string Password { get; set; }
public string ErrorMessage { get; set; }
}
and also my controller is below;
public ActionResult Index()
{
Session["User"] = null;
LoginModel model = new LoginModel();
return View(model);
}
[HttpPost]
public ActionResult Index(LoginModel data)
{
string user = System.Configuration.ConfigurationManager.AppSettings["UserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["Password"];
if (data.UserName == user && data.Password == password)
{
Session["User"] = "1";
return RedirectToAction("Index", "Home");
}
else
{
data.ErrorMessage = "Incorrect password or username entered. Please try again.";
return View(data);
}
}