如何检查会话过期或不并重定向用户使用javascript到登录页面 [英] How to check session is expired or not and redirect user to login page using javascript

查看:155
本文介绍了如何检查会话过期或不并重定向用户使用javascript到登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用ASP.Net MVC的Web应用程序。在我的应用程序,我使用了一些许多AJAX调用通过了我的申请GET / POST的某些功能的数据。对于一些功能我显示的iFrame弹出。我的问题是,当会议在我的申请已过期,我重定向用户到登录页面,但如果用户试图访问的的iFrame弹出打开而不是重定向到登录我弹出打开网页,登录页面里面,否则它的正常工作的功能。那么,什么是检查会话最好的办法是过期的或不和重定向用户从弹出的iFrame里面的登录页面。在code打开的iFrame弹出窗口如下:

 函数ShowPopup(URL,DIALOGTITLE,W,H){/ *设置对话框* /
$(#对话)。对话框({
    标题:DIALOGTITLE,
    的AutoOpen:假的,
    模式:真实,
    可调整大小:假的,
    宽度:W,
    高度:H,
    开:功能(EV,UI){
        / *设置URL中的iframe *开/
        $('#ContentIframe')ATTR('src'中,URL)。
    }
});/ *打开对话框* /
$('#对话)对话框(开放)。
}


解决方案

可以使用下面的逻辑做...

写在下面的登录页面code块

 <脚本类型=文/ JavaScript的>
在window.onload =函数()
{
    如果(窗口!= window.top)
    {
        window.top.location =YourLoginPageURL;
        window.close()的;    }
};
< / SCRIPT>

如果登录页面在IFRA打开

(窗口!= window.top)将返回true

希望它能帮助

I am developing web application using ASP.Net MVC. In my application I am using some many ajax calls through out my application to Get/Post data for some functionality. For some functionality I am showing iframed popup. My issue is that when session is expired in my application I am redirecting user to login page but if user try to access functionality that opens in iframed popup instead of redirecting to login page my popup opens with login page inside it otherwise it's working properly. So what is best way to check session is expired or not and redirecting user to login page from inside of iframed popup. The code for opening iframed popup is as follow:

function ShowPopup(Url, DialogTitle, W, H) {

/* Setting for dialog box */
$("#dialog").dialog({
    title: DialogTitle,
    autoOpen: false,
    modal: true,
    resizable: false,
    width: W,
    height: H,
    open: function (ev, ui) {
        /* Setting URL to open in iframe */
        $('#ContentIframe').attr('src', Url);
    }
});

/* Opening dialog box */
$('#dialog').dialog('open');
}

解决方案

It can be done using following logic...

Write following block of code in your Login Page

 <script type="text/javascript">
window.onload=function()
{
    if (window!=window.top) 
    { 
        window.top.location = "YourLoginPageURL";
        window.close();

    }
};
</script>

(window!=window.top) will return true if Login page is opened in IFra

Hope it helped

这篇关于如何检查会话过期或不并重定向用户使用javascript到登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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