Introduction
The Automatic Multi-Browser Logout feature is designed to address this need by providing a robust and convenient solution to safeguard your account. This innovative feature ensures that when you log out from one browser, you are automatically logged out from all other active sessions, regardless of the device or platform.
the Automatic Multi-Browser Logout feature enhances security and offers a seamless user experience. Whether you are using multiple devices for work. this feature ensures that your sessions are consistently terminated across all browsers, protecting your sensitive information from unauthorized access. With benefits such as enhanced security, convenience, and a consistent logout experience
To achieve the functionality in ASP.NET CORE MVC, you can follow these steps.
Step 1. Add a Model for store session ID with a particular user basis.
public class Session
{
public int? UserId { get; set; }
public string Sessionid { get; set; }
}
Step 2. Define methods for Insert, Delete, and Get session ID and userID in IRepositary.cs
IRepositary.cs
public interface ICommonRepository : IDisposable, IRepository
{
Task<CustomerResult> SessionInsert(Session customer);
Task<CustomerResult> DeleteSessionId(string sessionid, int userid);
Task<IEnumerable<Session>> GetSessionExist(string sessionid, int userid);
}
Step 3. Implementation of all Interfaces as defined in Step-2 as we required session insert in each login and check session Exist and Delete session if Logoutby user in Browser.
Repository. cs
public class CommonRepository : RepositoryBase, ICommonRepository
{
public Task<CustomerResult> SessionInsert(Session customer)
{
DynamicParameters param = new DynamicParameters();
object[] objArray = new object[] {
//"int_CustomerId", customer.CustomerId!=null?customer.CustomerId:0,
"ACTION","A",
"UserId",customer.UserId,
"Session",customer.Sessionid
};
param = objArray.ToDynamicParameters("PAR_OUT");
var result = Connection.Query<string>("USP_SESSIONSTORE", param, commandType:
System.Data.CommandType.StoredProcedure);
string response = param.Get<string>("PAR_OUT");
CustomerResult customerResult = new CustomerResult() { Remark = response };
return Task.FromResult(customerResult);
}
public Task<CustomerResult> DeleteSessionId(string sessionid, int userid)
{
DynamicParameters param = new DynamicParameters();
object[] objArray = new object[] {
//"int_CustomerId", customer.CustomerId!=null?customer.CustomerId:0,
"ACTION","B",
"Session",sessionid,
"UserId",userid
};
param = objArray.ToDynamicParameters("PAR_OUT");
var result = Connection.Query<string>("USP_SESSIONSTORE", param, commandType: System.Data.CommandType.StoredProcedure);
string response = param.Get<string>("PAR_OUT");
CustomerResult customerResult = new CustomerResult() { Remark = response };
return Task.FromResult(customerResult);
}
public async Task<IEnumerable<Session>> GetSessionExist(string session, int userid)
{
DynamicParameters _params = new DynamicParameters();
_params.Add("ACTION", "C");
_params.Add("Session", session);
_params.Add("UserId", userid);
var result = await Connection.QueryAsync<Session>("USP_SESSIONSTORE", _params, commandType: CommandType.StoredProcedure);
return result;
}
}
Join the conversation! Your thoughts help the community grow.