Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

need help on logout fuction to call when browser or browser tab will close or session will end

$
0
0

Sir/madam i am very weak in java script  and i tried to get know how to logout my application when browser or browser tab or session will expired but failed and i am totally confused because i am learner of these stuff in java script or j query or ajax but i made successfully login and logout tracking using button click event of asp.net. So expecting help regarding that how i call the following function when browser closed or browser tab closed or session expired.

this is the function i made and by call of this function there a stored procedure call so i keep the server time of logout to my table so please help me out by giving a demo code please.

main thing is the code has been written in side the .cs page of my master page of project

Function for logout: 

public void logout()
{
List<CommonDTO> list = new List<CommonDTO>();
paramobj = new CommonDTO();
paramobj.PARAMNAME = "@User_LoginId";
paramobj.PARAMVALUE = Session["uid"].ToString();
paramobj.PARAMTYPE = 2;
list.Add(paramobj);
paramobj = new CommonDTO();
paramobj.PARAMNAME = "@Type";
paramobj.PARAMVALUE = "O";
paramobj.PARAMTYPE = 2;
list.Add(paramobj);
paramobj = new CommonDTO();
paramobj.PARAMNAME = "@IP";
paramobj.PARAMVALUE = ""; // here i send the ip as null beacuse i am not using for logout fuction and i use the value type to validate and update table 
paramobj.PARAMTYPE = 2;
list.Add(paramobj);
CommonClass.InsertData("PROC_LOGIN_DETAILS", list);
Session["uid"] = "";
Session["pwd"] = "";
Response.Redirect("../../Index.aspx");
}

// this is click event where i am firing the fuction
protected void logout_click(object sender, EventArgs e)
{
logout();
}

Stored procedure for updation of table :

USE [OCPL_DB]
GO
/****** Object: StoredProcedure [dbo].[PROC_LOGIN_DETAILS] Script Date: 03-11-2017 11:08:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[PROC_LOGIN_DETAILS]
@User_LoginId varchar(20),
@IP varchar(50),
@Type varchar(2),
@p_chrv_out varchar(2) output
AS
BEGIN
if(@Type='I')
BEGIN
DECLARE @LogDate varchar(15), @LogTime varchar(15)
DECLARE @GETDATELOGIN AS DATETIME = GETDATE() ;
select @LogDate= (select CONVERT(VARCHAR(4),DATEPART(YEAR, @GETDATELOGIN))
       + '/'+ CONVERT(VARCHAR(2),DATEPART(MONTH, @GETDATELOGIN))
       + '/' + CONVERT(VARCHAR(2),DATEPART(DAY, @GETDATELOGIN)))
select @LogTime=(SELECT CONVERT(time,@GETDATELOGIN))
INSERT INTO Login_Details(User_LoginId,IP,LogDate,LogTime) VALUES(@User_LoginId,@IP,@LogDate,@LogTime);
set @p_chrv_out=1;

END
else
BEGIN
DECLARE @GETDATELOGOUT AS DATETIME = GETDATE() ;
select @LogDate= (select CONVERT(VARCHAR(4),DATEPART(YEAR, @GETDATELOGOUT))
       + '/'+ CONVERT(VARCHAR(2),DATEPART(MONTH, @GETDATELOGOUT))
       + '/' + CONVERT(VARCHAR(2),DATEPART(DAY, @GETDATELOGOUT)))
select @LogTime=(SELECT CONVERT(time,@GETDATELOGOUT))
update Login_Details set LogDate=@LogDate,LogoutTime=@LogTime where User_LoginId=@User_LoginId
set @p_chrv_out=1;

END
END

 


Viewing all articles
Browse latest Browse all 5678

Trending Articles