OpenLightGroup Blog

rss

Blogs from OpenLightGroup.net


Silverlight Keep Logged In: Prevent pages from timing out

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.





Comments are closed.