Restricting user access in asp.net <p>I am working on asp.net application. I want only logged in users to access the Game page. When the users log in, the id and pass are authenticated from the SQL then they are logged in. and I want the logged in users to have an access to Games.aspx.</p> <p>Here is the login code,</p> <pre><code> public partial class Login : System.Web.UI.Page { //"Data Source=MUNIZA\\SQLEXPRESS;Initial Catalog=LD_Server;Integrated Security=True"; protected void Page_Load(object sender, EventArgs e) { lbInfo.Enabled = false; } public bool IsAuthenticated { get { return Convert.ToBoolean(Session["sIsAuthenticated"] ?? false); } set { Session["sIsAuthenticated"] = value; } } protected void Button1_Click(object sender, EventArgs e) { string strcon = "Data Source=MUNIZA\\SQLEXPRESS;Initial Catalog=LD_Server;Integrated Security=True"; SqlConnection con = new SqlConnection(strcon); SqlCommand com = new SqlCommand("spStudentProfile", con); com.CommandType = CommandType.StoredProcedure; SqlParameter p1 = new SqlParameter("RegNo", TextBox2.Text); SqlParameter p2 = new SqlParameter("Password", TextBox1.Text); com.Parameters.Add(p1); com.Parameters.Add(p2); con.Open(); SqlDataReader rd = com.ExecuteReader(); if (rd.HasRows) { IsAuthenticated = true; rd.Read(); Response.Redirect("~/Games.aspx"); } else { IsAuthenticated = false; lbInfo.Enabled = true; lbInfo.Text = "Invalid username or password."; } } </code></pre> <p>It is the login code on every page, </p> <pre><code> &lt;% string url = "~/Login.aspx", text = "Log in"; if (Convert.ToBoolean(Session["sIsAuthenticated"] ?? false)) { url = "~/Home.aspx"; text = "Log out"; } %&gt; &lt;a href="&lt;%: ResolveUrl(url) %&gt;"&gt;&lt;%: text %&gt;&lt;/a&gt; &lt;/div&gt; </code></pre>