Check Session Timeot for Whole Application

1. Create a BasePage.cs in App_Code  and write the following code

        protected void Page_Init(object sender, EventArgs e)
        {
            if (Context.Session != null)
            {
                if (Session.IsNewSession)
                {
                    HttpCookie newSessionIdCookie = Request.Cookies["ASP.NET_SessionId"];
                    if (newSessionIdCookie != null)
                    {
                        string newSessionIdCookieValue = newSessionIdCookie.Value;
                        if (newSessionIdCookieValue != string.Empty)
                        {
                            //This means Session was timed Out and New Session was started
                            Response.Redirect("Home.aspx");
                        }
                    }
                }
            }
        }

2. Inherit this basepage on all the aspx pages such as
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using VAS.BLL;
using VAS.DAL;
using VAS.PL;

public partial class _Default: BasePage
{
         ///body
}

Comments

  1. Thanks for sharing Sir..i hope u keep posting!!

    ReplyDelete

Post a Comment

Popular posts from this blog

Display multiple marker point on Google Map with same location or same Longitude,Latitude

How to refresh parent page on close of popup window by toolbar close button

Implementing Zoom functionality in asp.net