Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: cookie trouble


Message #1 by "Roberts, Ben" <Ben.Roberts@a...> on Wed, 23 Oct 2002 16:43:51 -0600
Hola all,

I'm having trouble with the following snippet of code:

	if(!wf.EmptyRecordSet(dr))
	{
		Response.Cookies["bsr"].Expires = new DateTime(2003,12,31);
		Response.Cookies["bsr"]["username"] = username.Text;
		Response.Cookies["bsr"]["password"] = password.Text;
		string un = Request.Cookies["bsr"]["username"];
		Label3.Text = un;
		//Response.Redirect("/family.index2.aspx");
	}
	else
		Label3.Text = "Invalid Login... Try Again";

the code compiles just fine, but I'm either not storing anything in the
cookie or trying to access the cookie's value incorrectly because all i'm
getting back is a blank string (not null, though.)

Any pointers?

BTW, I would prefer to use a jar to hold my cookies in (to keep them
separate across multiple sites that i develope), but if I can't that's okay
to.

TIA,
Be Well,
Ben

Message #2 by Elissa Setarehshenas <elissasetareh@y...> on Thu, 24 Oct 2002 06:51:34 -0700 (PDT)
Ben, 
You're missing a few key lines of code.
Try this


Response.Cookies["bsr"].Expires = new
DateTime(2003,12,31);
Response.Cookies["bsr"]["username"] =username.Text;
Response.Cookies.Add(bsr);

HttpCookie myCookie = Request.Cookies["bsr"];
string un= myCookie.Values["username"];

Hope this helps,
Elissa
			
--- "Roberts, Ben" <Ben.Roberts@a...> wrote:
> Hola all,
> 
> I'm having trouble with the following snippet of
> code:
> 
> 	if(!wf.EmptyRecordSet(dr))
> 	{
> 		Response.Cookies["bsr"].Expires = new
> DateTime(2003,12,31);
> 		Response.Cookies["bsr"]["username"] 
> username.Text;
> 		Response.Cookies["bsr"]["password"] 
> password.Text;
> 		string un = Request.Cookies["bsr"]["username"];
> 		Label3.Text = un;
> 		//Response.Redirect("/family.index2.aspx");
> 	}
> 	else
> 		Label3.Text = "Invalid Login... Try Again";
> 
> the code compiles just fine, but I'm either not
> storing anything in the
> cookie or trying to access the cookie's value
> incorrectly because all i'm
> getting back is a blank string (not null, though.)
> 
> Any pointers?
> 
> BTW, I would prefer to use a jar to hold my cookies
> in (to keep them
> separate across multiple sites that i develope), but
> if I can't that's okay
> to.
> 
> TIA,
> Be Well,
> Ben
> 
> 
> ---
> Beginning ASP.NET Databases using VB.NET
> http://www.wrox.com/ACON11.asp?ISBN=1861006195
> 
> Beginning ASP.NET Databases using C#
> http://www.wrox.com/ACON11.asp?ISBN=1861007418
> 
> These books look at how we can create data-centric
> ASP.NET 
> applications. Requiring some basic knowledge of
> ASP.NET, 
> Access and SQL the authors guide you through the
> process 
> of connecting and consuming information in a variety
> of 
> ways. They are packed full of excellent illustrative
> code 
> examples, demonstrating important fundamental
> principles.


__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

  Return to Index