重定向到另一个页面在javascript中不起作用
大家好。在我的 MVC 应用程序中,我尝试重定向到登录页面,但它没有重定向,并且我收到“服务器错误”。
这是 javascript:
<script type="text/javascript">
function keepAlive() {
window.clearTimeout(window.sessionKeepAlive);
window.sessionKeepAlive = window.setTimeout(function() {
if(confirm('refresh session?')) {
// submit coding required
} else {
//window.location="/Employee/~/Account/LogOn"
//location.replace("/Employee/~/Account/LogOn");
window.location.href = '<%= Url.Action( "Logout", "Account" ) %>';
}
}, <%= (Session.Timeout - 19) * 60 * 1000 %>);
}
keepAlive();
</script>
另外,我需要用户按下“确定”按钮并继续的代码。
Hi folks. In my MVC application, I am trying to redirect to a login page, however it is not redirecting and I am getting a "server error".
Here is the javascript:
<script type="text/javascript">
function keepAlive() {
window.clearTimeout(window.sessionKeepAlive);
window.sessionKeepAlive = window.setTimeout(function() {
if(confirm('refresh session?')) {
// submit coding required
} else {
//window.location="/Employee/~/Account/LogOn"
//location.replace("/Employee/~/Account/LogOn");
window.location.href = '<%= Url.Action( "Logout", "Account" ) %>';
}
}, <%= (Session.Timeout - 19) * 60 * 1000 %>);
}
keepAlive();
</script>
Also, I need the code for if the user presses the 'ok' button and it continues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我而言,我更喜欢在中添加 web.config 的完整路径链接
,并在 Global.asax 中声明应用程序变量
,现在我可以在整个站点中使用这些变量。在你的情况下,你可以简单地使用
In my case, I prefer to add the full path link to web.config in
And declare an application variable in Global.asax in
And now I can use the variables in the whole site. In you case, you can simply use by
确保您重定向到的位置包含协议,即
对于第二位,您可以对心跳页面进行 ajax 调用以刷新会话
Make sure that the location you're redirecting to includes the protocol i.e.
For the second bit you can make an ajax call to a heartbeat page to refresh the session