title: after logout from users account all page shows error
body: <p>I have vb.net web application in which if users are logged in than all other pages working fine but the time I log out from account than it gets error in all pages.  I know the page getting values from cookies but if cookies is empty then it's getting null &amp; so cause the error page</p>
  
  <p>Error : System.NullReferenceException: Object reference not set to an instance of an object.</p>
  
  <p>VB Code for any pageload</p>
  
  <pre><code>Dim var, Type As String
          var = Server.HtmlEncode(Request.Cookies("chkusername").Value)
          Type = Server.HtmlEncode(Request.Cookies("User_Type").Value)
          Dim LogIn, LogOut, listup As Control
          Dim BtnProfile As Button = Page.Master.FindControl("myAccount")
  
          LogIn = Master.FindControl("login")
          LogOut = Master.FindControl("logout")
          listup = Master.FindControl("list")
  
          'not login
          If HttpContext.Current.Request.Cookies("chkusername") Is Nothing Then
              listup.Visible = True
              LogIn.Visible = True
              LogOut.Visible = False
              BtnProfile.Visible = False
  
              'login
          Else
              LogOut.Visible = True
              BtnProfile.Visible = True
              LogIn.Visible = False
              listup.Visible = False
  
          End If
  </code></pre>
  
  <p>Login Page code</p>
  
  <pre><code>Dim User, Pass As String
          If selectbusinesstype.SelectedValue.ToString = "0" Then
              Response.Write("&lt;script language='javascript'&gt;alert('Select login type first');&lt;/script&gt;")
          ElseIf selectbusinesstype.SelectedValue = "Hospitals" Then
  
              Try
                  If loginId.Text &lt;&gt; "" And password.Text &lt;&gt; "" Then
  
                      Dim str As String = "select * from hospitals where username='" + loginId.Text + "' and Password='" + password.Text + "';"
                      Dim cmd As New MySqlCommand(str, con)
                      con.Open()
                      Dim da As New MySqlDataAdapter(cmd)
                      Dim ds As New DataSet
                      da.Fill(ds)
                      con.Close()
                      User = ds.Tables(0).Rows(0)("username")
                      Pass = ds.Tables(0).Rows(0)("password")
  
                      If ds.Tables(0).Rows.Count &gt; 0 Then
  
                          If User = loginId.Text.ToString And Pass = password.Text.ToString Then
                              Response.Cookies("User_Type").Value = "Hospitals"
                              Response.Cookies("chkusername").Value = loginId.Text
                              Response.Redirect("hospital-profile.aspx?user=" + Request.Cookies("chkusername").Value)
                          Else
                              Response.Write("&lt;script language='javascript'&gt;alert('User name or password is invalid');&lt;/script&gt;")
                          End If
                      Else
                          Response.Write("&lt;script language='javascript'&gt;alert('User name or password is invalid');&lt;/script&gt;")
                      End If
                  Else
                      Response.Write("&lt;script language='javascript'&gt;alert('Enter All the Details');&lt;/script&gt;")
                  End If
  
              Catch ex As Exception
                  Response.Write("&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;")
                  Response.Write(ex)
                  con.Close()
              End Try
  </code></pre>