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 CPallini 405
1 Sergey Alexandrovich Kryukov 272
2 OriginalGriff 165
3 George Jonsson 159
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,860
2 CPallini 5,135
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | 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