会话结束时调用操作方法
Call an action method when session ends
我想在会话超时时调用尚未创建其视图的注销操作方法。
我已经为会话超时编写了一个脚本,但我不知道如何调用操作方法,因为我得到的所有方法,如 window.location
等都定位了视图。
<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>
这是我要调用的目标控制器操作
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");
}
我已经尝试了所有方法knew.Suggest我如何只点击动作方法。
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);
或
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";
}
请注意确保:您已将 Session.Timeout 设置为整数值
然后您可以发出 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
}
});
}
我想在会话超时时调用尚未创建其视图的注销操作方法。
我已经为会话超时编写了一个脚本,但我不知道如何调用操作方法,因为我得到的所有方法,如 window.location
等都定位了视图。
<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>
这是我要调用的目标控制器操作
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");
}
我已经尝试了所有方法knew.Suggest我如何只点击动作方法。
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);
或
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";
}
请注意确保:您已将 Session.Timeout 设置为整数值
然后您可以发出 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
}
});
}