Organizational Research By

Surprising Reserch Topic

how to check whether session is expired or not in asp net


how to check whether session is expired or not in asp net  using -'c#,asp.net'

i ve specified the session time out in web.config file..when the session is timeout im not getting redirect to login page but i am geting error saying object reference not set to an instance.

can any one tell me the solution for this?
    
asked Sep 24, 2015 by rajeevr642
0 votes
14 views



Related Hot Questions



Government Jobs Opening

"); } else { lblUnit.Text = Session["sessUnit_code"].ToString(); LblGrcSr.Text = Session["sessgrcSerial"].ToString(); } }
answered Sep 24, 2015 by jekbishnoi
0 votes

this way many people detect session has expired or not. the below code may help u.

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("Login.aspx");
                    }
                }
            }
        }
    }
answered Sep 24, 2015 by mannumits1

...