title: Cookies and session in asp.net
body: <p>I am creating a login and the storing the user details in a cookie using this code</p>
  
  <pre><code>if (ValidateUser(txtUserName.Value,txtUserPass.Value) )
  {
     //string useremail = Convert.ToString(txtUserName.Value);
     Session.Add("useremail", txtUserName.Value);
     FormsAuthenticationTicket tkt;
     string cookiestr;
     HttpCookie ck;
     tkt = new FormsAuthenticationTicket(1, txtUserName.Value, DateTime.Now, 
       DateTime.Now.AddMinutes(30), chkPersistCookie.Checked, "your custom data");
     cookiestr = FormsAuthentication.Encrypt(tkt);
     ck = new HttpCookie(FormsAuthentication.FormsCookieName, cookiestr);
     if (chkPersistCookie.Checked)
       ck.Expires=tkt.Expiration; 
     ck.Path = FormsAuthentication.FormsCookiePath; 
     Response.Cookies.Add(ck);
  }
  </code></pre>
  
  <p>I am also creating a session  Session.Add("useremail", txtUserName.Value); 
  After succesfull authentication it is redirected to user.aspx
  I want to read the useremail value in the user.aspx page but when I tried to access the value in the user page it is not showing useremail field.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          if
              (Session["useremail"] == null) Response.Redirect("Home.aspx");
          else
  
              BindGridView(useremail);
      }
  </code></pre>
  
  <p>And this is my webconfig:  </p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;&lt;forms name=".YAFNET_Authentication" loginUrl="Home.aspx" protection="All" timeout="43200" cookieless="UseCookies"/&gt;&lt;/authentication&gt;
  </code></pre>
  
  <p>Correct me if i am doing any wrong. And also please tell me how to pass the useremail value to the user.aspx page so that I can pass that value to gridview function</p>