silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight超时退出怎么实现?(AuthticationTimeOut)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

Silverlight用户用表单身份认证FormsAuthentication登录以后,如果一定的时间没有动作(Idle)就超时退出登录,这样的功能怎么实现?(关于Silverlight FormsAuthentication用户登录,可以参BusinessApplication,新建一个BusinessApplication即可)。好了,来实现这个超时退出功能。 新的类FormsWithTim


Silverlight用户用表单身份认证FormsAuthentication登录以后,如果一定的时间没有动作(Idle)就超时退出登录,这样的功能怎么实现?(关于Silverlight FormsAuthentication用户登录可以参BusinessApplication,新建一个BusinessApplication即可)。好了,来实现这个超时退出功能

新的类FormsWithTimeoutAuthentication继承FormsAuthentication

?
@H_761_772@
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
@H_197_126@ 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 @H_262_190@FormsWithTimeoutAuthentication : FormsAuthentication
@H_262_194@     @H_262_190@{
@H_262_194@         private @H_262_190@DispatcherTimer idleTimer;
@H_262_194@         private int @H_262_190@minutesIdle;
@H_262_194@         private bool @H_262_190@idle;
@H_262_194@         private bool @H_262_190@attached = false @H_262_190@;
@H_262_194@         public @H_262_190@FormsWithTimeoutAuthentication()
@H_262_194@             @H_262_190@: this @H_262_190@(20)
@H_262_194@          @H_262_190@{ }
@H_262_194@          public @H_262_190@FormsWithTimeoutAuthentication( int @H_262_190@idleminutes)
@H_262_194@          @H_262_190@{
@H_262_194@              @H_262_190@IdleminutesBeforeTimeout = idleminutes;
@H_262_194@              @H_262_190@idleTimer = new @H_262_190@DispatcherTimer();
@H_262_194@              @H_262_190@idleTimer.Interval = TimeSpan.Fromminutes(1);
@H_262_194@              @H_262_190@idleTimer.Tick += new @H_262_190@EventHandler(idleTimer_Tick);
@H_262_194@          @H_262_190@}
@H_262_194@          public int @H_262_190@IdleminutesBeforeTimeout
@H_262_194@          @H_262_190@{
@H_262_194@              get @H_262_190@;
@H_262_194@              set @H_262_190@;
@H_262_194@          @H_262_190@}
@H_262_194@          protected override @H_262_190@LoginResult EndLogin(IAsyncResult asyncResult)
@H_262_194@          @H_262_190@{
@H_262_194@              @H_262_190@var result = base @H_262_190@.EndLogin(asyncResult);
@H_262_194@              if @H_262_190@(result.Loginsuccess == true @H_262_190@)
@H_262_194@              @H_262_190@{
@H_262_194@                  if @H_262_190@(!attached) AttachEvents();
@H_262_194@                  @H_262_190@minutesIdle = 0;
@H_262_194@                  @H_262_190@idleTimer.Start();
@H_262_194@              @H_262_190@}
@H_262_194@              return @H_262_190@result;
@H_262_194@          @H_262_190@}
@H_262_194@          protected override @H_262_190@logoutResult Endlogout(IAsyncResult asyncResult)
@H_262_194@          @H_262_190@{
@H_262_194@              @H_262_190@idleTimer.Stop();
@H_262_194@              return base @H_262_190@.Endlogout(asyncResult);
@H_262_194@          @H_262_190@}
@H_262_194@          private void @H_262_190@AttachEvents()
@H_262_194@          @H_262_190@{
@H_262_194@              @H_262_190@attached = true @H_262_190@;
@H_262_194@              @H_262_190@Application.Current.RootVisual.MouseMove += new @H_262_190@mouseEventHandler(RootVisual_MouseMovE);
@H_262_194@              @H_262_190@Application.Current.RootVisual.KeyDown += new @H_262_190@KeyEventHandler(RootVisual_KeyDown);
@H_262_194@          @H_262_190@}
@H_262_194@          private void @H_262_190@RootVisual_KeyDown( object @H_262_190@sender,KeyEventArgs E)
@H_262_194@          @H_262_190@{
@H_197_126@ @H_262_194@              @H_262_190@idle = false @H_262_190@;
@H_262_194@          @H_262_190@}
@H_262_194@          private void @H_262_190@RootVisual_MouseMove( object @H_262_190@sender,MouseEventArgs E)
@H_262_194@          @H_262_190@{
@H_262_194@              @H_262_190@idle = false @H_262_190@;
@H_262_194@          @H_262_190@}
@H_262_194@          private void @H_262_190@idleTimer_Tick( object @H_262_190@sender,EventArgs E)
@H_262_194@          @H_262_190@{
@H_262_194@              if @H_262_190@(idle == true @H_262_190@)
@H_262_194@              @H_262_190@{
@H_262_194@                  @H_262_190@minutesIdle += idleTimer.Interval.minutes;
@H_262_194@                  if @H_262_190@(minutesIdle >= IdleminutesBeforeTimeout)
@H_262_194@                  @H_262_190@{
@H_262_194@                  @H_262_190@}
@H_262_194@              @H_262_190@}
@H_262_194@              else
@H_262_194@              @H_262_190@{
@H_262_194@                  @H_262_190@minutesIdle = 0;
@H_262_194@              @H_262_190@}
@H_262_194@              @H_262_190@idle = true @H_262_190@;
@H_262_194@          @H_262_190@}
@H_262_194@          private void @H_262_190@logout()
@H_262_194@          @H_262_190@{
@H_262_194@              //这里是你自己的退出登录代码,我这里是调用JS,刷新页面而已
@H_262_194@               @H_262_190@HtmlPage.Window.Invoke( "refreshSL" @H_262_190@, "Invoke" @H_262_190@);
@H_262_194@          @H_262_190@}
@H_262_194@      @H_262_190@}

修改App.xaml,修改WebContext表单认证模式

Silverlight超时退出怎么实现?(AuthticationTimeOut)

   
   
1 < Application 2 x:Class ="MyAppSl.App" 3 xmlns ="http://scheR_822_11845@as.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x ="http://scheR_822_11845@as.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 >

Silverlight超时退出怎么实现?(AuthticationTimeOut)

我这里配置的Idle两分钟就超时退出登录,可以自己配置超时时间。实现的效果就是用户登录Silverlight应用以后,如果一定的时间没有动作(Idle)就超时退出登录,返回登录页面

大佬总结

以上是大佬教程为你收集整理的Silverlight超时退出怎么实现?(AuthticationTimeOut)全部内容,希望文章能够帮你解决Silverlight超时退出怎么实现?(AuthticationTimeOut)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。