Kullanacağım çalışan kimliğini saklayan empid adlı bir kurabim var. Ancak, herhangi bir çerezin değerini almaya çalıştığımda, değeri otomatik olarak sıfırlanır ve bu kod, sayfa tarafından miras alınan kısmi bir sınıftan gelir. Ne ben tüm veritabanı ile ilgili kod içeren bir sınıf oluşturmak ve Response
nesneden everypageÇerezler otomatik olarak boşaltılıyor
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDbConn"].ToString()))
{
using (SqlCommand cmd = new SqlCommand())
{
try
{
cn.Open();
SqlDataReader conReader;
conReader = null;
mycomment.Text = Response.Cookies["empid"].Value;
// cmd.CommandText = "Select * from comments where c_from = " + Response.Cookies["cid"] + " and c_to = "+ Response.Cookies["empid"].ToString();
cmd.Connection = cn;
mycomment.Text = cmd.CommandText;
cmd.CommandType = CommandType.Text;
conReader = cmd.ExecuteReader();
while (conReader.Read())
{
mycomment.Text += conReader[3].ToString();
}
}
catch (Exception ex)
{
Console.Write(ex);
}
finally
{
cn.Close();
}
}
}
}