Telerik RadNotification: Notification / Session Timeout notification

http://demos.telerik.com/aspnet-ajax/notification/examples/sessiontimeout/defaultcs.aspx

  • 1. The ShowInterval property is set to automatically show the popup as time before session timeouts as you desire. This simple setting replaces using any timers at all.
  • 2. The Value property is set to the desired url of the page which shows when session expires. You could of course evaluate it on the client or send it through different techniques, even hard - code it, but this way is more elegant and the notification takes care of sending it to the client where you can easily extract it.
  • 3. Declare a handler for the OnCallbackUpdate event (it could be simply blank) and call the client method update() when you want to restart the session. This will automatically perform a callback to the server - codeless boost of performance.
  • 4. If the session should not be restarted, simply use the client get_value() method to extract the url and redirect to it.

  <telerik:RadNotification ID="RadNotification1" runat="server" Position="Center" Width="240"
        Height="100" OnCallbackUpdate="OnCallbackUpdate" OnClientShowing="OnClientShowing"
        OnClientHidden="OnClientHidden" LoadContentOn="PageLoad" AutoCloseDelay="60000"
        Title="Continue Your Session" TitleIcon="" Skin="Office2007" EnableRoundedCorners="true">
        <ContentTemplate>
            <div class="infoIcon">
                <img src="Img/infoIcon.jpg" alt="info icon" /></div>
            <div class="notificationContent">
                Time remaining:  <span id="timeLbl">60</span>
                <telerik:RadButton Skin="Office2007" ID="continueSession" runat="server" Text="Continue Your Session"
                    Style="margin-top: 10px;" AutoPostBack="false" OnClientClicked="ContinueSession">
                </telerik:RadButton>
            </div>
        </ContentTemplate>
    </telerik:RadNotification>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Threading;
using System.IO;

namespace Telerik.Web.Examples.Notification.SessionTimeout
{
    public partial class DefaultCS : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //set the expire timeout for the session 
                Session.Timeout = 2;
                //configure the notification to automatically show 1 min before session expiration
                RadNotification1.ShowInterval = (Session.Timeout - 1) * 60000;
                //set the redirect url as a value for an easier and faster extraction in on the client
                RadNotification1.Value = Page.ResolveClientUrl("SessionExpired.aspx");
            }
        }

        protected void OnCallbackUpdate(object sender, RadNotificationEventArgs e)
        {
             
        }
    }
}

Note:Keeping Your ASP.NET Session Alive Using jQuery

When you're working with the ASP.NET Session, it's important to remember that the session can timeout. The time before timing out is normally configured in the web.config file. Sometimes sessions time out at the most inconvenient time for your users. They could start a page, fill in some data, go to lunch then come back, click next and one of two things happen. Either the user is redirected back to the starting screen, or they'll get the ASP.NET yellow screen of death. That means the developer is not checking the session object for a null reference before using it. One workaround for this is to keep the users session alive by running a small snippet of code which updates a session object. I'll show you how to do this when you're building an ASP.NET MVC website.
Also, forcing the session state to always be alive can be bad. you need to let the session state get killed off otherwise you will run out of memory and the entire application pool will end up recycling and affecting users who are on the site and not just the sessions that don't have users viewing them.

http://www.dotnetcurry.com/ShowArticle.aspx?ID=453

http://www.primaryobjects.com/cms/article86.aspx

public class KeepSessionAlive : IHttpHandler, IRequiresSessionState
{
      public void ProcessRequest(HttpContext context)
      {
            context.Session["KeepSessionAlive"] = DateTime.Now;
      }
 
      public bool IsReusable
      {
            get
            {
                return false;
            }
      }
}

<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script language="javascript" type="text/javascript">
        $(function() {
            setInterval(KeepSessionAlive, 10000);
        });
 
        function KeepSessionAlive() {           
            $.post("/Shared/KeepSessionAlive.ashx", null, function() {
                $("#result").append("<p>Session is alive and kicking!<p/>");
            });   
        }   
    </script>
    <h2>Will my session die?</h2>   
    <div id="result"></div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值