silverlight session wcf object string application
前边一篇文章中,说了一下WCF和Asp.net的session共享,现在实现Silverlight的过期退出和WCF服务session失效的同步方案。
Silverlight的bussiness模板中已经包含了超时认证的部分,现作为借鉴,实现了WCF服务端session失效和Silverlight过期的同步。
1. 在web.config中设置session过期的时间:
[HTML] view plain copy print ? <sessionState mode="InProc" stateConnectionString= "tcpip=127.0.0.1:42424" cookieless="false" timeout="60"/> 2. 在aspx的页面中读取其配置过期时间到silverlight中。
[csharp] ? public partial class Default : System.Web.UI.Page { protected overrIDe voID OnLoad(EventArgs e) { if (!User.IDentity.IsAuthenticated) { string url = Request.Url.ToString(); url = url.Replace("&", "%26"); string urlBase64 = Convert.ToBase64String(System.Text.EnCoding.Default.GetBytes(url)); string urlRedirect = string.Format("{0}?ReturnUrl={1}", FormsAuthentication.LoginUrl, urlBase64); Response.Redirect(urlRedirect); return; } else { UserID = httpContext.Current.User.IDentity.name; @H_301_201@// 读取session过期时间 int formTimeOut =(int)FormsAuthentication.Timeout.TotalMinutes; Timeout = httpContext.Current.Session.Timeout >= formTimeOut ? formTimeOut : httpContext.Current.Session.Timeout; base.OnLoad(e); } voID Page_Load(object sender, EventArgs e) { } public string UserID { get; set; } int Timeout { } 3.把Timeout传人参数到silverlight端:
? param name="initParams" value="userID=<%=UserID%>,timeOut=<%=Timeout%>"/> 4.在silverlight中读取过期时间值,进行过期退出实现
? private voID Application_Startup("timeOut"]); FormsWithTimeoutAuthentication formsWithTimeoutAuthentication = new FormsWithTimeoutAuthentication(_timeOut); @H_301_201@// 短于服务端 formsWithTimeoutAuthentication.EndLogin(true);
formsWithTimeoutAuthentication 类得实现:
? class FormsWithTimeoutAuthentication { private dispatcherTimer IDleTimer; int minutesIDle; bool IDle; bool attached = false; private CommonProxy.CommonServicesClIEnt commomProxy = null; public FormsWithTimeoutAuthentication() : this(20) { } public FormsWithTimeoutAuthentication(int IDleMinutes) { IDleMinutesBeforeTimeout = IDleMinutes; IDleTimer = new dispatcherTimer(); IDleTimer.Interval = TimeSpan.FromMinutes(1); IDleTimer.Tick += new EventHandler(IDleTimer_Tick); } int IDleMinutesBeforeTimeout { get; set; } voID EndLogin(bool loginRes) if (loginRes == true) { if (!attached) AttachEvents(); minutesIDle = 0; IDleTimer.Start(); } voID Endlogout() IDleTimer.Stop(); voID AttachEvents() attached = true; @H_301_201@//Application.Current.RootVisual.MouseMove += new MouseEventHandler(RootVisual_MouseMove); Application.Current.RootVisual.KeyDown += new KeyEventHandler(RootVisual_KeyDown); Application.Current.RootVisual.MouseleftbuttonUp += new MousebuttonEventHandler(RootVisual_MouseleftbuttonUp); Application.Current.RootVisual.MouseRightbuttonDown += new MousebuttonEventHandler(RootVisual_MouseRightbuttonDown); Application.Current.RootVisual.MouseWheel += new MouseWheelEventHandler(RootVisual_MouseWheel); voID RootVisual_MouseWheel(false; voID RootVisual_MouseRightbuttonDown( RootVisual_MouseleftbuttonUp( RootVisual_KeyDown( RootVisual_MouseMove( IDleTimer_Tick( (IDle == minutesIDle += IDleTimer.Interval.Minutes; if (minutesIDle >= IDleMinutesBeforeTimeout) { logout(); } else minutesIDle = 0; voID logout() Endlogout(); //这里是你自己的退出登录代码,我这里是调用WCF的配置的退出地址,退出界面,刷新页面而已 commomProxy = new CommonServicesClIEnt(); commomProxy.GetConfigValuebyConfigKeyCompleted += (sender, e) => { if(e.Error == null) { if (!string.IsNullOrEmpty(e.Result)) HTMLPage.Window.Navigate(new Uri( e.Result, UriKind. absolute)); } }; commomProxy.GetConfigValuebyConfigKeyAsync("logoutRedirectUrl"); } 总结
以上是内存溢出为你收集整理的Silverlight的过期退出和WCF服务session失效的同步方案。全部内容,希望文章能够帮你解决Silverlight的过期退出和WCF服务session失效的同步方案。所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)