Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to manage session through global.asax file because I dont want to write a session check method for every page, I want all the request by default should be validated from global.asax. I need to check my custom session in session_start to see valid user. I am using outproc (state server) for storing session.

I tried the code but after checking the session it doent check the session for the next load, I have below scenario.

1) Open any URL (If session fails it should redirect to login page)
2) After landing on Login page I change the URL in address bar and for this time code doesnt come to session_start to check valid session.

What I have tried:

protected void Session_Start(object sender, EventArgs e)
        {
            try
            {
                if (HttpContext.Current.Session["clientinfo]!=null))
                {

                }
                else
                {
                    //FormsAuthentication.SignOut();
                    //HttpContext.Current.Session.Abandon();
                    Response.Redirect("some page");
                }

            }
            catch
            {
            }
        }
Posted
Updated 6-Feb-17 16:53pm
v3

Hi,

Why don't you use filters to do this?

Check the below URL.
Check Session Timeout by Using ActionFilters in MVC[^]
 
Share this answer
 
Create a common method for check session get call where you required
C#
/// <summary>
        /// Method to check sesssion.
        /// </summary>
        /// <param name="sessionName"></param>
        /// <returns></returns>
        public static bool CheckSession(string sessionName)
        {
                      if(!string.IsNullOrEmpty((string)HttpContext.Current.Session[sessionName]))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900