NOT ABLE TO CREATE COOKIE ON IE8.IT IS WORKING FINE WITH FIREFOX

Posted by Harsh_rc under Silverlight on 3/15/2011 | Points: 10 | Views : 4698 | Status : [Member] | Replies : 12
i am not able to create cookie on Internet Explorer 8.it is working fine with firefox.

i am using

Response.Cookies.Add()

and for fetching

Request.Cookies




Responses

Posted by: Karthikanbarasan on: 3/15/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
What error you are getting?

Thanks
Karthik
www.f5Debug.net

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 3/15/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi harsh

show ur full requirement . .what the error come now . . tha's the way to add cookies are .

databaseusername.Value = TextBox1.Text;
Response.Cookies.Add(databaseusername);



Best Regard's
Prabhakar

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/15/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
i have a function that creates and delete the Cookie , that i am using in my silverlight project. i am not currently at home because i am busy with my weeding things, i will reply to your post when i get home.

Thank you for posting at Dotnetfunda
[Administrator]

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Harsh_rc on: 3/16/2011 [Member] Starter | Points: 25

Up
0
Down
i am not able to create cookie on internet explorer.but it is working fine with firefox.
this is my brief code..

protected void Button1_Click(object sender, EventArgs e)
{

var ss = Request.Cookies;
Response.Write(ss["name"].Value.ToString());

}

protected void Button2_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("name");
cookie.Value = "harshal";
cookie.Expires = DateTime.Now.AddMinutes(30);
Response.Cookies.Add(cookie);
}

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Harsh_rc on: 3/16/2011 [Member] Starter | Points: 25

Up
0
Down
i am not able to create cookie on internet explorer.but it is working fine with firefox.
this is my brief code..

protected void Button1_Click(object sender, EventArgs e)
{

var ss = Request.Cookies;
Response.Write(ss["name"].Value.ToString());

}

protected void Button2_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("name");
cookie.Value = "harshal";
cookie.Expires = DateTime.Now.AddMinutes(30);
Response.Cookies.Add(cookie);
}

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Harsh_rc on: 3/16/2011 [Member] Starter | Points: 25

Up
0
Down
this code run successfully on Mozilla Firefox but it is not working on internet explorer

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/16/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Harsh_rc always use the Code formating option on your toolbar to format your code.

Use the Following code to create and delete a cookie in Silverlight

 public static void DeleteCookie(string key)

{
//string oldCookie = HtmlPage.Document.GetProperty("cookie") as String;
DateTime expiration = DateTime.UtcNow - TimeSpan.FromDays(1);
string cookie = String.Format("{0}=;expires={1}", key, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
}


  public static void SetCookie(string key, string value)

{

// string oldCookie = HtmlPage.Document.GetProperty("cookie") as String;
DateTime expiration = DateTime.UtcNow + TimeSpan.FromDays(2000);
string cookie = String.Format("{0}={1};expires={2}", key, value, expiration.ToString("R"));
HtmlPage.Document.SetProperty("cookie", cookie);
}


   /// 

/// Retrieves an existing cookie
///
/// cookie key
/// null if the cookie does not exist, otherwise the cookie value
public static string GetCookie(string key)
{
string[] cookies = HtmlPage.Document.Cookies.Split(';');
key += '=';
foreach (string cookie in cookies)
{
string cookieStr = cookie.Trim();
if (cookieStr.StartsWith(key, StringComparison.OrdinalIgnoreCase))
{
string[] vals = cookieStr.Split('=');

if (vals.Length >= 2)
{
return vals[1];
}

return string.Empty;
}
}

return null;
}



Thank you for posting at Dotnetfunda
[Administrator]

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Harsh_rc on: 3/16/2011 [Member] Starter | Points: 25

Up
0
Down
same thing happening i dont know why.is there any problem releted with firewall or what..
with this code IE create browser cookie only.but when i close the browser and open it again i am getting "OBJECT REFERENCE NOT SET TO INSTANCE OF OBJECT"

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Harsh_rc on: 3/16/2011 [Member] Starter | Points: 25

Up
0
Down
please test this code.

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/16/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
i use this code everyday in my SL app. its working. make sure that your Browser allows Cookies

Thank you for posting at Dotnetfunda
[Administrator]

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Harsh_rc on: 3/23/2011 [Member] Starter | Points: 25

Up
0
Down
ya it is allowing .

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/24/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
so is it working now ?

Thank you for posting at Dotnetfunda
[Administrator]

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response