Click here to Skip to main content
16,019,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
the logout button clear the session using the code below and then redirect to login
page.

C#
FormsAuthentication.SignOut();
            Session.Clear();
            Session.Abandon();


Then, each page call a function ValidateSession() in a class checkLogIn as
CheckLogIn.ValidateSession() in page load event.

the function ValidateSession() as below,

C#
public static void ValidateSession()
        {
            try
            {
                string sUserId = System.Web.HttpContext.Current.Session["UserId"].ToString();
            }
            catch (Exception oException)
            {
                System.Web.HttpContext.Current.Session["UserId"] = "sessionOut";
                System.Web.HttpContext.Current.Response.Redirect("~/Account/Login.aspx");

            }
            
        }



Then, check the session, Session["LoginId"] in page load event of login page.
as below

C#
if (Session["UserId"] != null)
           {
               ScriptManager.RegisterStartupScript(this, this.GetType(), "alertscript", "find()", true);
           }



But the Session["UserId"]==null.why?

Thanks..
Posted
Updated 21-Dec-12 5:22am
v2
Comments
it.sudhiryadav 21-Dec-12 8:30am    
ya correct rohit. there no value is assigned to session.
hasbina 21-Dec-12 11:26am    
SORRY,ACTUALLY I FORGET TO CHANGE IT IN ValidateSession().ASSIGN
Session["UserId"]="SessionOut" not Session[LoginId].

1 solution

Its seems like you're not assigning value to Session["User_ID"].. So try
C#
Session["User_ID"] = UserNameTxt.Text ;

Hope it will solve your problem.. :)
 
Share this answer
 
Comments
hasbina 21-Dec-12 11:28am    
@Krunal Rohit
sir,i forgot to change it in my question.assigning value to
Session["UserId"]="sessionout".but not get it at Login.aspx page load.

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