Click here to Skip to main content
Rate this: bad
good
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 1:44am
hasbina1.2K
Edited 21-Dec-12 5:22am
v2
Comments
it.sudhiryadav at 21-Dec-12 8:30am
   
ya correct rohit. there no value is assigned to session.
hasbina at 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.. Smile | :)
  Permalink  
Comments
hasbina at 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
0 Sergey Alexandrovich Kryukov 271
1 OriginalGriff 223
2 nv3 50
3 VJ Reddy 45
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2014
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