Please refer following code,
After successful login add following code to add user data in session.
HttpContext.Current.Session["UserID"] = data.UserId;
HttpContext.Current.Session["Email"] = data.Email;
Add following code in master page.
public bool checkAuthentication
{
get;
set;
}
protected void Page_Load(object sender, EventArgs e)
{
if (checkAuthentication)
{
if ((Session["UserID"] + "") == "")
{
Response.Write("<script type=\"text/javascript\">" +
"window.parent.location = '" + ConfigurationManager.AppSettings["SiteUrl"] + "login?loginUrl=' + window.parent.location + '&mode=session';" +
"</script>");
Response.End();
}
}
}
Add following code in each child page where you want to authenticate user session.
protected void Page_PreInit(object sender, EventArgs e)
{
this.Master.checkAuthentication = true;
}
On click of logout button redirect to logout page.
Add following code on page load of logout.aspx
protected void Page_Load(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect(ConfigurationManager.AppSettings["SiteUrl"] + "login?mode=logout",true);
}
Hope this may help you.