Avoid PostBack C# MVC RRS feed

  • Question

  • Hello community, I have a web application in C # MVC and front in HTML with JS, I have a method to close session but when I return to the Login and press the "back" button of the browser I return to the session with all the data, I share the code

    Code Login HTML (FRONT):

    <form method="post" action="@Url.Action("Admin", "Admin")">
           <div class="form-group">
              <input type="text" class="form-control input-lg" placeholder="Usuario" name="txtUs" />
           <div class="form-group">
              <input type="password" class="form-control input-lg" placeholder="Contraseña" name="txtPas" />
           <div class="form-group col-md-6 col-lg-offset-3 text-center">
              <input type="submit" class="btn btn-lg btn-info" value="Entrar" />                              

    Code that validates the login (BehindCode):

    private bool isSession(string u, string p)
         bool isValid = false;
         using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, ConfigurationManager.AppSettings["ActiveDirectory"]))
             //Valida si existe en el directorio activo           
             isValid = pc.ValidateCredentials(u, p);
         if (isValid)
             isValid = ma.isSessionValid(u);
         return isValid;

    In this way if it is valid it returns "true" and enters the index of the page, loading a session variable

    Session["login"] = true

    And to close the session I use the following code

    public ActionResult LogOut()
       Response.AppendHeader("Cache-Control", "no-store");
       // probé con esta linea pero tampoco funciona
       // FormsAuthentication.SignOut();
       return RedirectToAction("Login", false);

    This return to the login, but when pressing the "back" key of the browser it returns to the previous page without going through the controller of said action, in ASP.NET I used

       //si la pagina esta regresando por postback cerrar sesión

    Someone knows how I can avoid this PostBack from the server side, validate that the session is not recovered by giving it back, I have searched several pages and can not find a solution in C # MVC, if they have any idea or article (English or Spanish) I can serve, I thank you.

    • Edited by Javier Insuasti Thursday, January 18, 2018 1:05 PM Extra Text
    • Moved by CoolDadTx Thursday, January 18, 2018 3:11 PM ASP.NET related
    Thursday, January 18, 2018 1:04 PM

All replies