gpt4 book ai didi

javascript - session 结束时调用操作方法

转载 作者:行者123 更新时间:2023-11-28 18:09:25 24 4
gpt4 key购买 nike

我想调用 LogOut 操作方法,由于 session 超时,我尚未创建该方法的 View 。

我已经为 session 超时编写了一个脚本,但我不知道如何调用操作方法,因为我拥有的所有方法(如 window.location 等)都可以定位 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>

这是我要调用的目标 Controller 操作

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");
}

我已经尝试了我所知道的所有方法。建议我如何只点击操作方法。

最佳答案

然后你可以发出一个ajax请求,例如:

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
}
});
}

关于javascript - session 结束时调用操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41954172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com