Session_END - Logout versus Session Time out
HiI 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