1

I want to call LogOut action method whose View i have not created as the session times out.

I have written a script for session time out but i dont know how to call action method because all the methods i have got like window.location etc locates the view.

    <script>
            //session end

        var sessionTimeoutWarning = @Session.Timeout;

        var sTimeout = parseInt(sessionTimeoutWarning) * 60 * 1000-55000;
        setTimeout('SessionEnd()', sTimeout);

    /* Here I want To call that AgentLogOut Method*/

        function SessionEnd() {
            alert("Session Is Going To End in 1 min Please Login Again1");

            window.location = "/Agent/AgentLogIn";
        }
</script>

And this the Target Controller Action to which I want to call

public ActionResult AgentLogOut()
        {
            string  SessionId = Session["LogInSession"].ToString();
            string OType = "LogOut";
            ProcedureName = "SP_Crud";
            XElement xl = new XElement("data",
                new XAttribute("otype", OType),
                new XElement("sessionId", SessionId),
                new XElement("agentIp", AgentIp)
                );
            objDal.ExecuteNonQuery(ProcedureName, CommandType.StoredProcedure, new MySqlParameter("@xml", xl.ToString()));
            Session.Clear();
            Session.Abandon();

            return RedirectToAction("AgentLogIn","Agent");
        }

I have tried all ways which i knew.Suggest me how to hit only the action method.

Dashanan
  • 122
  • 3
  • 16

2 Answers2

2

then you can make a ajax request like :

function SessionEnd() 
{
    $.ajax({
    type: "post",
    url: "/Agent/AgentLogIn",
    data:{data:value},
    success:function(response){
    //do some stuff like login page redirection
    },
    error:function(){
    //do some stuff like login page redirection
    }
  });
}
1
  var sessionTimeoutWarning = @Session.Timeout;

    var sTimeout = parseInt(sessionTimeoutWarning) * 60 * 1000-55000;
    setTimeout(function SessionEnd() {
        alert("Session Is Going To End in 1 min Please Login Again1");
       window.location = "/Agent/AgentLogIn";
    }, sTimeout);

OR

    var sessionTimeoutWarning = @Session.Timeout;

    var sTimeout = parseInt(sessionTimeoutWarning) * 60 * 1000-55000;
    setTimeout(SessionEnd, sTimeout);



    function SessionEnd() {
        alert("Session Is Going To End in 1 min Please Login Again1");
        window.location = "/Agent/AgentLogIn";
    }

note make sure : you have set Session.Timeout with integer value

  • Script Portion is working well. Tell me how to call the action method. – Dashanan Jan 31 '17 at 10:40
  • have you tried window.location = "/Agent/AgentLogIn"; you should try adding base url of your project –  Jan 31 '17 at 10:51
  • Yes i have tried but this also needs to have a view atleast but i dont want to create a view for this i just want to call that action method and insert that data into the database. – Dashanan Jan 31 '17 at 11:14