Silverlight超时退出怎么实现?(AuthticationTimeOut)
来源:互联网 发布:如何修改手机淘宝评价 编辑:程序博客网 时间:2024/04/29 10:25
Silverlight用户用表单身份认证FormsAuthentication登录以后,如果一定的时间没有动作(Idle)就超时退出登录,这样的功能怎么实现?(关于Silverlight FormsAuthentication用户登录,可以参考BusinessApplication,新建一个BusinessApplication即可)。好了,来实现这个超时退出功能。
新的类FormsWithTimeoutAuthentication继承FormsAuthentication
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
public
class
FormsWithTimeoutAuthentication : FormsAuthentication
{
private
DispatcherTimer idleTimer;
private
int
minutesIdle;
private
bool
idle;
private
bool
attached =
false
;
public
FormsWithTimeoutAuthentication()
:
this
(20)
{ }
public
FormsWithTimeoutAuthentication(
int
idleMinutes)
{
IdleMinutesBeforeTimeout = idleMinutes;
idleTimer =
new
DispatcherTimer();
idleTimer.Interval = TimeSpan.FromMinutes(1);
idleTimer.Tick +=
new
EventHandler(idleTimer_Tick);
}
public
int
IdleMinutesBeforeTimeout
{
get
;
set
;
}
protected
override
LoginResult EndLogin(IAsyncResult asyncResult)
{
var result =
base
.EndLogin(asyncResult);
if
(result.LoginSuccess ==
true
)
{
if
(!attached) AttachEvents();
minutesIdle = 0;
idleTimer.Start();
}
return
result;
}
protected
override
LogoutResult EndLogout(IAsyncResult asyncResult)
{
idleTimer.Stop();
return
base
.EndLogout(asyncResult);
}
private
void
AttachEvents()
{
attached =
true
;
Application.Current.RootVisual.MouseMove +=
new
MouseEventHandler(RootVisual_MouseMove);
Application.Current.RootVisual.KeyDown +=
new
KeyEventHandler(RootVisual_KeyDown);
}
private
void
RootVisual_KeyDown(
object
sender, KeyEventArgs e)
{
idle =
false
;
}
private
void
RootVisual_MouseMove(
object
sender, MouseEventArgs e)
{
idle =
false
;
}
private
void
idleTimer_Tick(
object
sender, EventArgs e)
{
if
(idle ==
true
)
{
minutesIdle += idleTimer.Interval.Minutes;
if
(minutesIdle >= IdleMinutesBeforeTimeout)
{
Logout();
}
}
else
{
minutesIdle = 0;
}
idle =
true
;
}
private
void
Logout()
{
//这里是你自己的退出登录代码,我这里是调用JS,刷新页面而已
HtmlPage.Window.Invoke(
"RefreshSL"
,
"Invoke"
);
}
}
修改App.xaml,修改WebContext表单认证模式
1 <Application 2 x:Class="MyAppSL.App" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:app="clr-namespace:MyAppSL" 6 xmlns:appService="clr-namespace:MyAppSL.Services" 7 xmlns:Lng="clr-namespace:MyAppSL.Resources" 8 xmlns:appsvc="clr-namespace:System.ServiceModel.DomainServices.Client.ApplicationServices;assembly=System.ServiceModel.DomainServices.Client.Web" 9 Startup="Application_Startup"10 UnhandledException="Application_UnhandledException">11 12 <Application.ApplicationLifetimeObjects>13 <app:WebContext>14 <app:WebContext.Authentication>15 <appService:FormsWithTimeoutAuthentication IdleMinutesBeforeTimeout="2"/>16 </app:WebContext.Authentication>17 </app:WebContext>18 </Application.ApplicationLifetimeObjects>19 20 <!--原来是这样的-->21 <!--<Application.ApplicationLifetimeObjects>22 <app:WebContext>23 <app:WebContext.Authentication>24 <appsvc:FormsAuthentication />25 </app:WebContext.Authentication>26 </app:WebContext>27 </Application.ApplicationLifetimeObjects>-->28 29 </Application>
我这里配置的Idle两分钟就超时退出登录,可以自己配置超时时间。实现的效果就是用户登录Silverlight应用以后,如果一定的时间没有动作(Idle)就超时退出登录,返回登录页面。
- Silverlight超时退出怎么实现?(AuthticationTimeOut)
- Android实现App会话超时退出设计
- 用户长时间无操作 超时退出系统实现
- Silverlight 超时问题
- Silverlight 超时问题
- 关于ssh超时退出
- 怎么实现带超时功能的 connect 函数
- Silverlight中怎么实现类似MessageBox的弹出对话框
- 在JSP中怎么实现系统登录后的退出
- Session超时怎么判断
- 怎么判断数据库连接超时
- vi怎么退出
- 怎么退出整个框架
- 怎么退出整个框架
- 怎么退出整个框架
- Android怎么完全退出
- TortoiseSVN ,怎么退出登录。
- .php会员登录权限和超时退出
- JAVA程序员不可不注意的编码规范
- java nio缓冲器(转)
- java使用socket实现http简单get请求
- 别人发的小例子log4j
- java求n小时候的时间
- Silverlight超时退出怎么实现?(AuthticationTimeOut)
- 字符识别
- java 视频处理 mencoder
- ASP.NET之Datalist详解(分页)
- JQuery JSON 循环
- 请教高手
- 蛇年谈程序员发展之路
- hdu 2955 Robberies + LightOJ 1079 Just another Robbery (01背包 概率)
- Java Spring 配置文件报错