在使用QUI开发的业务系统中,如果长时间没操作,session过期后,再次操作系统超时会自动跳转到登陆页面,如果当前有一些操作没有保存,需要重新登录后再次填写信息,用户体验很不好!

为了避免超时后页面跳转到登录页面,我改善了一下:当超时后点击链接时弹出登录页面,用户在弹出的登陆页面登录后,他先前的一些操作不会丢失,可以继续操作。

注:2014-04-26做了一下改进,弹出的超时登录窗口用户名自动填上,不允许修改,这样在一定程度上防止其它用户进入看到自己操作。

下面是具体实现方式:

权限验证基类页

    public class AuthBasePage : BasePage
{
protected override void OnInit(EventArgs e)
{
//判断是否得到身份认证
//您也可以用session判断
if (null!=HttpContext.Current.User.Identity&&!HttpContext.Current.User.Identity.IsAuthenticated)
{
Response.Write("<script type=\"text/javascript\">");
Response.Write("var topWin = (function (p, c) {while (p != c) {c = p;p = p.parent}return c;})(window.parent, window);");
Response.Write("try{ topWin.openLoginWindow();}catch(e){window.location='/Login.aspx'}");
Response.Write("</script>");
Response.End();
}
HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
userData = authTicket.UserData;
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
       //此处使用了吉日嘎拉权限管理系统的单点登录
userInfo = javaScriptSerializer.Deserialize<BaseUserInfo>(userData);
userInfo.ServiceUserName = BaseSystemInfo.ServiceUserName;
userInfo.ServicePassword = BaseSystemInfo.ServicePassword;
base.OnInit(e);
}

 在QUI主框架页面,增加下面的JS代码

      //避免超时跳转到登录页面,使用户的操作丢失,造成不好的体验
function openLoginWindow() {
var diag = new top.Dialog();
diag.Title = "系统超时,您已经退出,请重新登录";
//窗口ID
diag.ID = "a1";
diag.URL = "/PageUtils/DialogLogin.aspx?companyName=<%=userInfo.CompanyName%>&userName=<%=userInfo.UserName%>";
diag.Width = 350;
diag.Height = 190;
diag.ShowCloseButton = false;
diag.ShowCancelButton = false;
diag.ShowOkButton = false;
diag.ButtonAlign = "center";
diag.AllowChangeIndex = false;
diag.show();
diag.addButton("btnRest", " 重 置 ", function () {
top.document.getElementById("_DialogFrame_a1").contentWindow.restForm();
//改变一下窗口背景
$("#_DialogBGMask").css("z-index", "-1").css("opacity", "1").empty().append("<img src='/system/images/screen/000.jpg' style='width:100%;height:100%' />");
});
diag.addButton("btnLogin", " 登 录 ", function () {
top.document.getElementById("_DialogFrame_a1").contentWindow.validateForm();
//改变一下窗口背景
$("#_DialogBGMask").css("z-index", "-1").css("opacity", "1").empty().append("<img src='/system/images/screen/000.jpg' style='width:100%;height:100%' />");
});
//改变一下窗口背景
$("#_DialogBGMask").css("z-index", "-1").css("opacity", "1").empty().append("<img src='/system/images/screen/000.jpg' style='width:100%;height:100%' />"); }

可以看到,在session超时后,打开新页面时会调用主框架的openLoginWindow()方法,弹出登录窗口层,这样就不会跳转到登录页面了,当然如果您刷新了主框架则会跳转到登陆页的。

弹出窗口DialogLogin.aspx 后台页面的关键代码

  public partial class DialogLogin : BasePage
{
protected string sitename = RequestString("sitename");
protected string username = RequestString("username");
protected string password = RequestString("password");
protected string act = RequestString("act");
protected void Page_Load(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace("act") && string.Equals("login", act, StringComparison.OrdinalIgnoreCase))
{
LoginResult loginResult = new LoginResult();
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
BaseUserInfo userInfo = null;
var userManager = new BaseUserManager(this.userInfo);
if (!string.IsNullOrWhiteSpace(sitename) && !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
{             //此处可以用您自己的登录方法。 我这里是使用了吉日嘎拉单点登录。
PermissionServiceSoapClient webPermission = new PermissionServiceSoapClient();
string jsonData = webPermission.LogOnByCompany(sitename, username, password);
dynamic json = JsonConvert.DeserializeObject(jsonData);
string statusCode = string.Empty;
string statusMessage = string.Empty;
string userData = string.Empty;
statusCode = (string)((dynamic)json)["StatusCode"];
statusMessage = (string)((dynamic)json)["StatusMessage"];
if (string.Equals("OK", statusCode, StringComparison.OrdinalIgnoreCase))
{
userData = json["UserInfo"].ToString();
userInfo = javaScriptSerializer.Deserialize<BaseUserInfo>(userData);
FormsAuthentication.SetAuthCookie(userInfo.UserName, true, FormsAuthentication.FormsCookiePath);
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userInfo.UserName, DateTime.Now, DateTime.Now.AddMinutes(20), false, userData);
FormsIdentity identity = new FormsIdentity(authTicket);
ManageCookies.AddCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
}
loginResult.Status = statusCode;
loginResult.Message = statusMessage;
}
else
{
loginResult.Status = "Fail";
loginResult.Message = "没有参数传入";
}
string result = javaScriptSerializer.Serialize(loginResult);
Response.Write(result);
Response.End(); }
//else
//{
// loginResult.Status = "Fail";
// loginResult.Message = "参数不明确";
//}
} /// <summary>
/// 登录结果
/// </summary>
class LoginResult
{
public string Status
{
set;
get;
}
public string Message
{
set;
get;
} }
}

  

弹出窗口DialogLogin.aspx 前台页面的关键代码

<div id="screenLock" class="timeOut">
<form id="form1" action="" showOnMouseOver="false">
<table width="100%">
<tr>
<td class="ali03" style="width:70px">站点:</td>
<td><input type="text" name="sitename" id="sitename" style="width:140px;" class="validate[required,length[0,20]] float_left" />
<span class="star float_left">*</span><div class="validation_info">请输入站点名称</div>
</td>
</tr>
<tr>
<td class="ali03">用户:</td>
<td><input type="text" name="username" id="username" style="width:140px;" class="validate[required,length[0,20]] float_left" />
<span class="star float_left">*</span><div class="validation_info">请输入用户名称</div>
</td>
</tr>
<tr>
<td class="ali03">密码:</td>
<td><input type="password" name="password" id="password" style="width:140px;" class="validate[required,custom[noSpecialCaracters]] float_left"/>
<span class="star float_left">*</span><div class="validation_info">请输入密码</div>
<input type="text" style="width:2px;display:none;"/>
</td>
</tr>
<tr>
<td ></td>
<td><span id="passInfo" class="red"></span></td>
</tr>
</table>
</form>
</div>
<script type="text/javascript">
//手动触发验证,被验证的表单元素是containerId容器里的。 可以验证整个表单,也可以验证部分表单。
function validateForm() {
var valid = $("#form1").validationEngine({ returnIsValid: true });
if (valid == true) {
loginDeal();
} else {
top.Dialog.alert('填写不正确,请按要求填写!');
}
}
//重置表单
function restForm() {
//$("#sitename").val("");
//$("#username").val("");
$("#password").val("");
//$('#myform')[0].reset();
}
//登录操作
function loginDeal() {
$.ajax({
type: "GET",
async: false,
url: "/PageUtils/DialogLogin.aspx",
data: {
"sitename": $("#sitename").val(),
"username": $("#username").val(),
"password": $("#password").val(),
"act": "login"
},
dataType: "json",
success: function (result) {
if (result) {
if (result.Status == "OK") {
//登录成功 关闭弹出窗口层
top.Dialog.close();
} else {
top.Dialog.alert("账号或密码错误" + result.Message);
}
} else {
top.Dialog.alert("出现系统错误");
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
top.Dialog.alert("出现系统错误");
}
});
} //手动触发验证
$(function () {
        $("#sitename").val("<%=Request["companyName"]%>").attr("disabled", true);
        $("#username").val("<%=Request["userName"]%>").attr("disabled", true);
$("#password").keydown(function (event) {
if (event.keyCode == 13) {
validateForm('#form1');
}
})
}) </script>
 

  

超时后点击链接时弹出的登陆页窗口效果

成功登录以后会关闭窗口层,显示最后操作的界面。

QUI操作超时弹出登录窗口登录的处理方式的更多相关文章

  1. js制作带有遮罩弹出层实现登录小窗口

    要实现的效果如下 点击“登录”按钮后,弹出登录小窗口,并且有遮罩层(这个名词还是百度知道的,以前只知道效果,却不知道名字) 在没有点击“登录”按钮之前登录小窗口不显示,点击“登录”按钮后小窗口显示,并 ...

  2. [转]C# 安装时弹出设置服务登录窗口

    本文转自:http://blog.csdn.net/prince_jun/article/details/38435887 安装服务时系统不要弹出设置服务登录窗口:在程序中将serviceProces ...

  3. C# 安装WindowsService时弹出设置服务登录窗口的解决方案

    使用SignalR实现消息推送,页面实时刷新,使用WindowsService作为SignalR的宿主,也就是作为一个消息服务器,在使用cmd命令安装的时候弹出设置服务登录的窗口,解决此问题的具体操作 ...

  4. ZH奶酪:Ionic中(弹出式窗口)的$ionicModal使用方法

    Ionic中[弹出式窗口]有两种(如下图所示),$ionicModal和$ionicPopup; $ionicModal是完整的页面: $ionicPopup是(Dialog)对话框样式的,直接用Ja ...

  5. ***小程序wx.getUserInfo不能弹出授权窗口后的解决方案

    微信更新api后,wx.getUserInfo在开发和体验版本都不能弹出授权窗口.微信文档说明: 注意:此接口有调整,使用该接口将不再出现授权弹窗,请使用 <button open-type=& ...

  6. javascript--自定义弹出登陆窗口(弹出窗)

    web开发中浏览器对象封装了诸如prompt.alert.confirm等弹出框,但是有的弹出框并不能满足开发需要,需要我们自己定义弹出框,诸如用户登陆框.消息提示框等.本文利用弹出用户登陆框示例,对 ...

  7. 创建一个弹出DIV窗口

    创建一个弹出DIV窗口 摘自:   http://www.cnblogs.com/TivonStone/archive/2012/03/20/2407919.html 创建一个弹出DIV窗口可能是现在 ...

  8. 009-定时关闭弹出广告窗口 By BoAi 20190414

    ;~ 定时关闭弹出广告窗口 By BoAi 20190414 ; ### 参数设置段 ######################################SingleInstance,forc ...

  9. js实现第一次打开网页弹出指定窗口(常用功能封装很好用)

    js实现第一次打开网页弹出指定窗口(常用功能封装很好用) 一.总结 1.常用功能封装:之前封装的cookie的操作函数非常好用,我自己也可以这么搞 二.js实现第一次打开网页弹出指定窗口 练习1:第一 ...

随机推荐

  1. PhoneGap搭建运行环境(3.2版本)

    一. 1.准备环境nodejs(http://nodejs.org/download/) 2.ant(http://ant.apache.org/bindownload.cgi) 3.Android ...

  2. 从根源上解析 Java volatile 关键字的实现

    1.解析概览 内存模型的相关概念 并发编程中的三个概念 Java内存模型 深入剖析Volatile关键字 使用volatile关键字的场景 2.内存模型的相关概念 缓存一致性问题.通常称这种被多个线程 ...

  3. sizeof 字符数组

    比较 #include <stdio.h> #include <string.h> int main(int argc, const char *argv[]) { char ...

  4. Xcode 4 插件制作入门

    转自:http://www.onevcat.com/2013/02/xcode-plugin/ 2014.5.4更新 对于 Xcode 5,本文有些地方显得过时了.Xcode 5 现在已经全面转向了 ...

  5. Linux下的vi编辑命令中查找·替换详解

    一.查找 查找命令 /pattern<Enter> :向下查找pattern匹配字符串 ?pattern<Enter>:向上查找pattern匹配字符串 使用了查找命令之后,使 ...

  6. Spark SQL应用

    Spark Shell启动后,就可以用Spark SQL API执行数据分析查询. 在第一个示例中,我们将从文本文件中加载用户数据并从数据集中创建一个DataFrame对象.然后运行DataFrame ...

  7. POJ 2421 Constructing Roads (最小生成树)

    Constructing Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/D Description There ar ...

  8. HDU 4911 Inversion (逆序数 归并排序)

    Inversion 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/A Description bobo has a sequen ...

  9. Unity3D之游戏暂停制作方法记录

    在游戏开发中我们一般都需要涉及到一个功能:游戏暂停,但是这里指的暂停仅仅是核心模块的暂停,并不是整个游戏都暂停,比如一些UI和UI上的动画与特效是不能被暂停的,整个游戏都暂停了玩家该如何继续游戏呢. ...

  10. Thinkphp框架 -- 短信接口验证码

    我用的是一款名叫 短信宝 的应用,新注册的用户可以免费3条测试短信,发现一个BUG,同个手机可以无限注册,自己玩玩还是可以的. 里面的短信接口代码什么信息都没有,感觉看得不是很明白,自己测试了一遍,可 ...