重定向到另一页在JavaScript工作 [英] Redirecting to another page not working in javascript

查看:142
本文介绍了重定向到另一页在JavaScript工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

乡亲喜。在我的MVC应用程序,我想重定向到一个登录页面,但它没有进行重定向,我得到一个服务器错误。

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".

下面是JavaScript:

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>

另外,我需要code表示,如果用户presses确定按钮,然后继续。

Also, I need the code for if the user presses the 'ok' button and it continues.

推荐答案

在我而言,我preFER添加在

In my case, I prefer to add the full path link to web.config in

<appSettings>
    <add key="BaseURL" value="http://localhost/" />
</appSettings>

和在Global.asax中声明应用程序变量

And declare an application variable in Global.asax in

protected void Application_Start()
{
    Application["BaseURL"] = System.Configuration.ConfigurationManager.AppSettings["BaseURL"];
}

现在,我可以在整个网站使用的变量。在你的情况下,你可以简单地通过

And now I can use the variables in the whole site. In you case, you can simply use by

window.location.href = '<%=Application["BaseURL"]%>account/logout';

这篇关于重定向到另一页在JavaScript工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆