Hi,
I want to store the search url as a cookie in client side and write this url back to the database.The code below is not showing any errors but it is not writing the url string in database.I tested individually with writing url in database it works fine.Just its not working when i was trying to do from cookie.So please give me if you have any suggestions.
//Javascript part
location.href = "<%=ub.Uri.ToString()%>?" + Math.random() + "#" + query.toString();
document.cookie ="kursearch=" + query.toString();
//c# Code part
protected void Page_Load(object sender, EventArgs e) {
String text = GetCookie("kursearch");
Storetxt(text);
}
public string GetCookie(string cookiename)
{
string cookyval = "";
try
{
cookyval = Request.Cookies[cookiename].Value;
}
catch (Exception e)
{
cookyval = "";
}
return cookyval;
}
public void Storetxt(String txt)
{
string connection = "Data Source=.\\SQLEXPRESS;Initial Catalog=PtsKuratlas;Integrated Security=True";
SqlConnection conn = null;
SqlCommand cmd = null;
try
{
conn = new SqlConnection(connection);
cmd = new SqlCommand("INSERT INTO gti_analytics (keywords) VALUES (@link)", conn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@link", txt);
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
if (cmd != null) cmd.Dispose();
if (conn != null)
{
if (conn.State == ConnectionState.Open) conn.Close();
conn.Dispose();
}
}
}