Recently, in my project, there was a requirement that when the session expired, the user redirects to the logout page. I did a lot of research and found convenient tricks that I am sharing in the post.
This code is for ASP.NET web form, but this technique can be used in any other language.
protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack) {
Response.AppendHeader("Refresh", (Session.Timeout * 60) + 5 + "; Url=SessionEnded.aspx");
}
}