|
|||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis article provides an BackgroundThe issue of session timeout is due to the implementation that data storing at
Figure 1. The scenario of Session Timeouts.
Listing 1. Set the Period of a Session <system.web>
<sessionState timeout="20" /> <!-- timeout specifies the period of a session -->
</system.web>
The author of “Detecting ASP.NET Session Timeouts1” presents a trick to let developers check to see if a user's session has expired. Moreover, the author suggests encapsulating the checking logic into a base page class, and once session timeouts occur, the subsequent request will be redirected to a page showing some informative messages to tell users what happened. In this way, all pages which use sessions can inherit this base page for reusing the code logic. However, this solution cannot be directly adopted by DNN Web application. ProblemUnder the DNN Framework, there is only one page, Default.apsx, available to the whole Web application. From a user's perspective, clicking a hyperlink seems to go to an individual page. However, DNN merely uses Default.apsx to dynamically populate all of the page's content from a database for all requests. The Default.apsx.cs has inherited a base page class provided by the DNN Framework so we cannot adopt the solution mentioned in the preceding section (multiple inheritance is not supported in C# and VB.NET). One may think of intrusively inserting the checking logic of session timeouts into Default.apsx.cs. This is not an appropriate solution because if you want to upgrade your DNN Web site, you must re-insert the code logic again. Having described the problem, let us discuss the refactored solution. SolutionWe begin with the review of the basic process of HTTP requests in ASP.NET. Each HTTP request is handled by an If we can use the checking logic in “Detecting ASP.NET Session Timeouts1” in a The checking logic provided by “Detecting ASP.NET Session Timeouts1” is intended to be wrapped in an HttpModule2, namely Listing 2. SessionTimeoutModule public class SessionTimeoutModule:IHttpModule
{
private HttpApplication app;
public void Init(HttpApplication context)
{
app = context;
app.PreRequestHandlerExecute += new EventHandler(app_PreRequestHandlerExecute);
}
void app_PreRequestHandlerExecute(object sender, EventArgs e)
{
if(app.Context.Session != null)
{
if (app.Context.Session.IsNewSession)
{
string szCookieHeader = app.Context.Request.Headers["Cookie"];
if (szCookieHeader != null && szCookieHeader.IndexOf(
"ASP.NET_SessionId") >= 0)
{
// Get current TabInfo
PortalSettings portalSettings = (
PortalSettings)app.Context.Items["PortalSettings"];
TabInfo tabInfo = portalSettings.ActiveTab;
// If this tab is not "SessionTimeout" tab
if (tabInfo.TabName != "SessionTimeout")
{
TabController tabController = new TabController();
tabInfo = tabController.GetTabByName("SessionTimeout",
portalSettings.PortalId);
app.Context.Response.Redirect(pageUrl,true);
}
}
}
}
}
public void Dispose()
{
}
}
Install SessionTimeoutModuleCopy the SessionTimoutModule.cs to the Listing 3. Install SessionTimeoutModule in web.config <httpmodules>
<add name="Personalization"
type="DotNetNuke.HttpModules.Personalization.PersonalizationModule,
DotNetNuke.HttpModules">
<add name="SessionTimeout" type="SessionTimeoutModule">
</add>
</add></httpmodules>
ConclusionWe have gone through the issue of tackling session timeouts on DNN, and provided a solution that implements a previous work with an References
History
|
||||||||||||||||||||||||||||||||