You must Sign In to post a response.
  • Category: ASP.NET

    Session_END - Logout versus Session Time out

    Hi

    I am working on asp.net and I am very much new to this

    My requirement is as follows
    I am working on the logout functionality specifically
    I was given two options which are as follows

    o The user clicking the logout link
    o The website getting timedout

    So for the both requirements, we have an additional functionality of logging the same in database. To achieve this I have written two methods

    Signoutuser()
    timeoutuser()
    I have been said by my lead to use session_End event to log an entry in the database table.
    So I have written the methods as follows

    private async Task SignoutUser()
    {
    try
    {
    FormsAuthentication.SignOut();
    Session.Clear();
    Session.Abandon();

    }
    catch
    {
    throw;
    }
    }



    private async Task timeoutuser ()
    {
    try
    {
    FormsAuthentication.SignOut();
    Session.Clear();
    Session.Abandon();
    }
    catch
    {
    throw;
    }
    }


    So when the session is abandoned session_End is automatically triggered and written the following code as follows.

    protected void Session_End()
    {
    if (Session != null)
    {
    var logger = new Logger();
    string name = System.Threading.Thread.CurrentPrincipal.Identity.Name.ToString()
    var loggerContext = new LoggerHttpContext(HttpContext.Current);
    string IpAddress = Dns.GetHostByName(Dns.GetHostName().ToString()).AddressList[0].ToString();
    string MachineName = System.Environment.MachineName.ToString();
    await logger.LogAudit("Logout", "TerminateUserSession ", name, null, IpAddress, MachineName);

    }
    }


    So below is my requirement
    when the session is timeout I want LogAudit to log as "TerminateUserSession"
    when the user clicks logout I want LogAudit to log as "logoutusersession"

    Exactly here I have the problem

    In Session_END() how can I differentiate whether the user has clicked logout or the session is timedout

    Note : I must use global.asax Session_END for logging purpose.
    I am scratching my head to resolve this .

    Please help me
  • #768609
    Hi,

    I suspect that Logout & Timeout both are buttons or linkbuttons right?

    You can store some unique value like Id, of those into session / hiddenfield then based on that value you can perform your task.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #768618
    No....Timeout is not a linkbutton or hyperlink ...
    when the website is left idle for more than 30 minutes then its timeout ...
    The problem is I am not able to get the session value in session_end ....
    In Session_END() - how can it recognize whether its timeout or logout(hyperlink)

    protected void Session_End()
    {
    if (session.timeout)
    {
    logger.LogAudit("Logout", "TerminateUserSession )
    }
    else if (logout is clicked)
    {
    logger.LogAudit("Logout", "LogoutUserSession )
    }
    }

    Hope I am clear now

  • #768619
    No....Timeout is not a linkbutton or hyperlink ...
    when the website is left idle for more than 30 minutes then its timeout ...
    The problem is I am not able to get the session value in session_end ....
    In Session_END() - how can it recognize whether its timeout or logout(hyperlink)

    protected void Session_End()
    {
    if (session.timeout)
    {
    logger.LogAudit("Logout", "TerminateUserSession )
    }
    else if (logout is clicked)
    {
    logger.LogAudit("Logout", "LogoutUserSession )
    }
    }

    Hope I am clear now


Sign In to post your comments