cookies in C#.net

liunx

Guest
I'm trying to save a cookie using the following code:

<%
String username=Request.Form["Username"];
String password=Request.Form["Password"];
String savelogin=Request.Form["SaveLogin"];
HttpCookie cookie = new HttpCookie("DashboardAdmin");
if (savelogin=="ON") //then
{
cookie["Login"]=username;
cookie["Password"]=password;
cookie.Expires = Convert.ToDateTime("Dec 31, 2020");
}
else
{
cookie.Expires = Convert.ToDateTime("Jan 1,2000");
}
//Add the Cookie
Response.Cookies.Add(cookie);
Response.Write("Cookie has been Added");
%>


When It runs through I do not see the cookie in the cookie folder. Are they stored in some other Place? Plus when I go back to the login to retrieve the cookie using "HttpCookie cookie = Request.Cookies["DashboardAdmin"];" I get "Cookie not found" when testing to see if cookie == null; Any ideas on what is wrong?

Thanks,
JoshI was able to get it to work by using:

HttpCookie objCookie=new HttpCookie("DashboardAdmin");
objCookie.Values.Add("Login",Request.Form["Username"]);
objCookie.Values.Add("Password",Request.Form["Password"]);
objCookie.Values.Add("SaveLogin",Request.Form["SaveLogin"]);
Response.Cookies.Add(objCookie);


Thanks,
Joshuse
Respond.AppendCookie(cookies);

it will send the cookie to client browser.
i'm not sure try with the above statement
 
Back
Top