Keep user logged in with Silverlight                 Print      Add Favorite     Add Watch     Contact Author

Creator: host   4/7/2012 10:23:27 PM    Author: Michael Washington   Source: http://www.dotnetnuke.com/Resources/Blogs/EntryId/2492/Silverlight-Keep-Logged-In-Prevent-pages-from-timing-out.aspx   Views: 274    0    0  
Tags:
Dotnetnuke Silverlight Dnn login


Posted by: Michael Washington
2/12/2010  

If you have a page that contains a lot of information for users to enter, you can run into a problem where their authentication will “time out”. Usually this authentication is set to expire after 20 minutes of “inactivity” (the user has not submitted a request to the web server). The problem is that if they, for example, click the Save button after their authentication has expired, their content is not saved and they are logged out of the site instead.

image

To prevent this, you can install the Silverlight Keep Logged In module. When you place it on a page, there is no UI just a Title.

image

You can go into Settings for the module and change them so that nothing appears at all on the page but the module will still work.

image

Note, it has to be set so that Registered Users have View Module permission.

Any page that the module is on will not “time out” for the user. The module works by making a “call” to a web service in the website every 10 minutes. It uses a hidden Silverlight application to do this.

Silverlight runs in the “context of the user’s web browser”, so if the user is logged in, the Silverlight application running on the web page is “logged in”. When it makes a request of the website, the website detects that the user is making a request and it refreshes the the users “authentication token”.

The Problem

When a DotNetNuke module displays it’s first page, or it’s “default page”, all other modules on the page are also displayed. If the Silverlight Keep Logged In module is on the page, the user will not “time out”. However, if any other page in a module is displayed, all other modules are not displayed. In this case, the Silverlight Keep Logged In module will not work.

In this case, it would be necessary to incorporate the Silverlight Keep Logged In module code into the code of the custom module. The module structure is simple:

image

There is a View.ascx control to launch the hidden Silverlight application (SilverlightKeepLoggedIn.xap), with a supporting Silverlight.js file. There is also a web service that contains this code:

<%@ WebService Language="C#" Class="SilverlightKeepLoggedIn.WebService" %> 

using System.Web.Services; 
using DotNetNuke.Entities.Users; 

namespace SilverlightKeepLoggedIn 
{ 
 [WebService(Namespace = "http://ADefWebserver.com/")] 
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
 public class WebService : System.Web.Services.WebService 
 { 
 [WebMethod] 
 public void KeepAlive() 
 { 
 // Calling this web method keeps the user active 
 } 
 } 
}

The Silverlight application uses the following code:

using System; 
using System.Windows.Controls; 
using SilverlightKeepLoggedIn.wsKeepLoggedIn; 
using System.ServiceModel; 

namespace SilverlightKeepLoggedIn 
{ 
 public partial class MainPage : UserControl 
 { 
 public MainPage() 
 { 
 InitializeComponent(); 
 // Set up timer 
 System.Windows.Threading.DispatcherTimer dt = 
 new System.Windows.Threading.DispatcherTimer(); 
 // Set to call every 10 minutes 
 dt.Interval = new TimeSpan(0, 0, 10, 0, 0); 
 // Set up event handler 
 dt.Tick += new EventHandler(dt_Tick); 
 // Start timer 
 dt.Start(); 
 } 

 void dt_Tick(object sender, EventArgs e) 
 { 
 // Call web service 
 CallWebService(); 
 } 

 private string GetWebserviceAddress() 
 { 
 string strXapFile = @"/ClientBin/SilverlightKeepLoggedIn.xap"; 
 string strBaseWebAddress = 
 App.Current.Host.Source.AbsoluteUri.Replace(strXapFile, ""); 
 return string.Format(@"{0}/{1}", strBaseWebAddress, "WebService.asmx"); 
 } 

 private void CallWebService() 
 { 
 // Set up web service call 
 WebServiceSoapClient objWebServiceSoapClient = 
 new WebServiceSoapClient(); 
 EndpointAddress MyEndpointAddress = new 
 EndpointAddress(GetWebserviceAddress()); 
 objWebServiceSoapClient.Endpoint.Address = MyEndpointAddress; 
 // Call web method 
 objWebServiceSoapClient.KeepAliveAsync(); 
 } 
 } 
}

 

Download the DotNetNuke module

You can download the DotNetNuke 4+ module at this link.


Rating People: 1   Average Rating:     
Comment List:


  No Record 


Post your comment

Your Name: Required
Your Mail: Email is used only to display Gravatar
Your Site:
CAPTCHA image
Enter the code shown above in the box below
Comment Info:         

     DnnModule.com is build to provide quality modules and skins, Some of them are free,some not. We wish these stuffs( free or not ) can be useful to you.

    Besides that, We also provide a full range of professional services, ranging from web site build, seo, system management, administration, support, senior consultancy and security services.   We act as if your development project or network was ours, with care and respect. We are not satisfied until it works the way you want it to, and we don't silently ignore found issues as somebody else's problem.