Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I want to get the ID or any user Details in session after i click on Logout button not after Login button.How I can i get it.I have the Code as follows:
XML
#region Events
       /// <summary>
       /// The page losd event of Site master page.
       /// </summary>
       /// <param name="sender">The object sender.</param>
       /// <param name="e">The event arguments.</param>
       protected void Page_Load(object sender, EventArgs e)
       {
           if (Session[KaizenConstants.CURRENTLOGGEDINUSER] == null)
           {
               Response.Redirect("Login.aspx");
           }


           if (!IsPostBack)
           {
               if (Session[KaizenConstants.CURRENTLOGGEDINUSER] == null)
               {
                   UserManagementController userManagementController = new UserManagementController();
                   IUserEntity user = UserManagementEntityCreator.GetUserEntity();
                   string userName = HttpContext.Current.User.Identity.Name;
                   user.NetworkId = userName.Substring(userName.IndexOf("\\") + 1);
                   currentUserID = user.NetworkId;
                   Result result = userManagementController.Get(user);
                   user = result.Entity as IUserEntity;

                   if (user.Id > 0)
                   {
                       Session[KaizenConstants.CURRENTLOGGEDINUSER] = result.Entity;
                   }
                   else
                   {
                       Response.Redirect("QCError.aspx");
                   }
               }
           }

       }


In jquery I have Code like This:
$(function () {
               $('#logButton').click(function () { Logout(); });
           });

           function Logout() {
               debugger;
               var currenturl = window.location.href;
               $.ajax({
                   url: currenturl + '/Logout',
                   type: 'POST',
                   contentType: 'application/json; charset=utf-8',
                   dataType: "json",
                   success: function (result) {
                       window.open('', '_self', '');
                       window.close();
                   },
                   error: function (error) {
                       window.open('', '_self', '');
                       window.close();
                   },
                   async: false
               });
           }
Posted
Comments
ZurdoDev 1-May-14 8:53am    
I'm confused. After they logout what ID are you expecting to get from a session? There isn't one anymore.
R Harshal 1-May-14 9:13am    
Sorry for making you confused.
I want to say For Example:if user is logged in for 15 min in Webpage and session get expired after some particular time ,so before session get expired and if user click anywhere in the page at that time , i want to show Message to user that your session is expired.this i want .Please help ME.
ZurdoDev 1-May-14 9:18am    
The best approach, in my opinion, is to use FormsAuthentication in web.config and in your C# code. Then let .Net handle it for you. When the session expires and they try to get to something they will be automatically taken to your login page.
Sampath Lokuge 1-May-14 9:14am    
What's your business requirement ?

1 solution

Use the Session_End event handler in Global.asax. This event fires when the user's session is expired.
C#
protected void Session_End(object sender, EventArgs e)
        {
// Retrieve your Session ID here
        }
 
Share this answer
 
Comments
R Harshal 1-May-14 11:59am    
Tanuj you are right .But i am not confident in Session ,So will you please tell me how to retreive session Id in Session_End event handler in Global.asax Please ..
Very thankful to u.
Tanuj Rastogi 1-May-14 12:04pm    
e.g. String username = (string)Session["Username"];
R Harshal 2-May-14 5:16am    
Thank you Tanuj.I got it.
Thanks a lot.
Tanuj Rastogi 2-May-14 11:32am    
Happy to solve your issue :)

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