重定向到另一页在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';