Session_End does not execute.

omegalove
omegalove used Ask the Experts™
on
when I log out


        protected void btnLogout_Click(object sender, EventArgs e)
        {
         

            /* Abandon session object to destroy all session variables */
            //this.Context.Session.Clear();
            //this.Context.Session.Abandon();

            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage();
            Response.Redirect(FormsAuthentication.LoginUrl);

        }

The Session_End does not get executed

private void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends.        
            // Note: The Session_End event is raised only when the sessionstate mode        
            // is set to InProc in the Web.config file. If session mode is set to StateServer         
            // or SQLServer, the event is not raised.   
            try
            {
                string FromUserName = Session["FromUserName"] == null ? null : Session["FromUserName"].ToString();
                if (FromUserName != null)
                {
                    int returnValue = 0;

                    try
                    {
                        returnValue = SQLOmegaLoveProvider.UpdateIsOnLineNow(FromUserName);
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                }

                Application.Lock();
                Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
                Application.UnLock();


                if (this.Session != null)
                    OnlineVisitorsContainer.Visitors.Remove(this.Session.SessionID);

            }
            catch (Exception ex)
            {
                throw (ex);
                // CF.Writeerrlog(Server.MapPath("err.txt"), ex.Message)
                // logof.send25("err", "err occured", "aminnagpure@gmail.com", ex.Message)
                // Gf.Writeerrlog(Server.MapPath("err.txt"), ex.Message)
            }

        }

        // Fires at the beginning of each request
        protected void Application_BeginRequest(object source, EventArgs e)
        {
        }

        protected void Application_EndRequest(Object sender, EventArgs e)
        {
            // update user activity at the end of each request
            // but only if the siteUser is already in the HttpContext
            // we don't want to lookup the user for little ajax requests
            // unless we have to for security checks
            HttpContext context = HttpContext.Current;
            if (context.Response.Status.Substring(0, 3).Equals("401"))
            {
                context.Response.ClearContent();
                context.Response.Write("You will be imideately redirected to PublicArea/AccessDenied.aspx");
                context.Response.Write("<script language=javascript>self.location='PublicArea/AccessDenied.aspx';</script>");
            }


            //   SiteUtils.TrackUserActivity();
        }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
in your code, you have commented the lines to end the session.
Uncomment the line in your code:

 this.Context.Session.Abandon();

Author

Commented:
k

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial