Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET Cookies Problem. 2

Status
Not open for further replies.

jrapp

Programmer
May 15, 2003
25
0
0
US
Hey everybody. The program that i'm writing makes use of cookies to track logins. When I run it from my machine (the "server") as the cookies save fine. When I try to run it from another machine, or even mine by going to the cookies no longer work and I get a "Object reference not set to an instance of an object" error. Here's what my code looks like:

'Now we make a small cookie to track the user.
Dim loginCookie As New HttpCookie("Login")

loginCookie.Values.Add("LoggedIn", "TRUE")
loginCookie.Values.Add("StoreID", storeID)
loginCookie.Values.Add("UserType", userType)
loginCookie.Domain = "my_computer"

Response.AppendCookie(loginCookie)

'Read the cookie
Dim loginCookie As New HttpCookie("Login")
loginCookie = Request.Cookies("Login")
Response.Write(loginCookie("LoggedIn") & "<BR>")
Response.Write(loginCookie("StoreID") & "<BR>")
Response.Write(loginCookie("UserType"))

The second line of the "read the cookie" is what throws the exception. I know there's no error checking on this, I'm just trying to get it running. Any help would be greatly appreciated!

Jeff Rapp
jrapp@sell2all.com
 
As I know, there's an issue in ASP.NET (or Win2003 Server ... I can't remember exactly) with cookies when the server name contains the character "_". It sounds odd, but I can bet anything that if you'll change the name of your machine from "my_computer" to "mycomputer" (or any other word that not contains the character "_") it will work.

[morning]
 
That was the problem. I'm using XP for my test server, so it must be a problem in asp.net. That is possibly the strangest error I've seen yet, definately a bug. Thanks for the help!

Jeff Rapp
jrapp@sell2all.com
 
Wow, this really is weird. Is this a bug of the .NET framework itself or XP?

Keith
 
Why not make use of .net built in authentication.
Form authentication gives you the way exactly what you are trying to do.
 
It seems that there's a problem about session objects too, not only with cookies.

[morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top