title: Displaying session state in masterpage for asp.net
body: <p>I am designing a website whish has common forms such as login,logout,registration,masterpage etc.I am maintaining session when user logs in.I want to show logout on menu bar which is in master page if user is logged in else login and register new menu should be displayed.But logout menu is not shown whether user is logged in or not.Any help would be thankful.</p>
  
  <p>login code:</p>
  
  <pre><code> protected void Button1_Click(object sender, EventArgs e)
      {
          String pass=TextBox2.Text;
                  SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename='C:\\Users\\aayush\\Documents\\Visual Studio 2010\\WebSites\\JustDial\\App_Data\\Database.mdf';Integrated Security=True;User Instance=True");
          con.Open();
          SqlCommand cmd = new SqlCommand("select * From shop where shop_email = @param1", con);       
          cmd.Parameters.AddWithValue("@param1", TextBox1.Text);
          SqlDataReader dr = cmd.ExecuteReader();
          while (dr.Read())
          {
  
              String pass2 = dr["shop_password"].ToString();
              if (pass.Equals(pass2))
              {
                  Session["email"] = dr["shop_email"].ToString();
                  Response.Redirect("home.aspx");            
              }
              else {
                  TextBox1.Text = "";
                  TextBox2.Text = "";
                  Label1.Text = "Invalid email id or password";         
               }
  
          }
  
          dr.Close();
          con.Close();
      }
  }
  </code></pre>
  
  <p>and menu bar code in master page:</p>
  
  <pre><code>&lt;ul&gt;
     &lt;li&gt;&lt;a href='home.aspx'&gt;&lt;span&gt;Home&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href='about.aspx'&gt;&lt;span&gt;About&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href='feedback.aspx'&gt;&lt;span&gt;Feedback&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;li&gt;&lt;a href='contact.aspx'&gt;&lt;span&gt;Contact&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
     &lt;%
         if (Session["email"] is bool &amp;&amp; (bool)Session["email"])
  
         {%&gt;
  
          &lt;li&gt;&lt;a href='logout.aspx'&gt;&lt;span&gt;Logout&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
         &lt;% }
  
         else {%&gt;
  
          &lt;li&gt;&lt;a href='login.aspx'&gt;&lt;span&gt;Login&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
       &lt;li class='last'&gt;&lt;a href='addShop.aspx'&gt;&lt;span&gt;Register&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
         &lt;%
         }
  
          %&gt;
  
  &lt;/ul&gt;
  </code></pre>