Click here to Skip to main content
12,626,014 members (26,489 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
the logout button clear the session using the code below and then redirect to login
page.

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,

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

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


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

Thanks..
Posted 21-Dec-12 2:44am
hasbina1.4K
Updated 21-Dec-12 6: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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Its seems like you're not assigning value to Session["User_ID"].. So try
Session["User_ID"] = UserNameTxt.Text ;
Hope it will solve your problem.. :)
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100