using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPages_Default : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uid"] == null && Session["AuthToken"] == null && Request.Cookies["AuthToken"] == null)
        {
            Response.Redirect("../Security/LoginPage.aspx");
        }
        else
        {
            if (Session["pageArea"] as string != "A")
            {
                if(!String.IsNullOrEmpty(Session["uid"] as string))
                    Helper.LogOut(Session["uid"].ToString());
                HttpContext.Current.Session.Clear();
                HttpContext.Current.Session.Abandon();
                //HttpContext.Current.Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));

                Response.Redirect("../Security/LoginPage.aspx");
            } 

            if (Session["uid"] == null || Session["AuthToken"] == null)
            {
                Response.Redirect("../Security/LoginPage.aspx");
            }

            if (!Session["AuthToken"].ToString().Equals(Request.Cookies["AuthToken"].Value))
            {
                Response.Redirect("../Security/LoginPage.aspx");

            }
            else
            {
                if (!IsPostBack)
                {
                    Label2.Text = DateTime.Now.Date.ToString("dd-MM-yyyy");
                    Label3.Text = DateTime.Now.TimeOfDay.ToString().Split('.')[0];
                    Label1.Text = Session["username"].ToString();
                    LabelVersion.Text = Helper.App_Version;
                }
            }
        }
    }
}
