473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

asp.net cookie domain problem solved

i noticed weird cookie problems when clients sometimes visit my site with
the www. prefix and sometimes without the prefix. I decided to start
setting the .domain property, but that doesnt work for localhost. So here
is my solution hopefully it saves someone some grief. Let me know if I
missed something obvious:

Response.Cookies.Add(WriteCookie("testUID", TextBox1.Text,
Request.Url.Host))
Public Function WriteCookie(ByVal strKey As String, ByVal strValue As
String, ByVal strHost As String) As HttpCookie

Dim cook As New HttpCookie(strKey, strValue)

cook.Expires = Now.AddYears(1)

If strHost <> "localhost" Then

Dim myArray As String()

myArray = strHost.Split(".")

If myArray.Length > 2 Then

'we only want the last two segments of the host name

strHost = myArray(myArray.Length - 2) & "." & myArray(myArray.Length - 1)

End If

cook.Domain = strHost

End If

WriteCookie = cook

End Function

Public Function DeleteCookie(ByVal strKey As String, ByVal strHost As
String) As HttpCookie

Dim cook As New HttpCookie(strKey)

cook.Expires = Now.AddYears(-30)

If strHost <> "localhost" Then

Dim myArray As String()

myArray = strHost.Split(".")

If myArray.Length > 2 Then

'we only want the last two segments of the host name

strHost = myArray(myArray.Length - 2) & "." & myArray(myArray.Length - 1)

End If

cook.Domain = strHost

End If

DeleteCookie = cook

End Function

Nov 17 '05 #1
0 1169

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rss | last post by:
SUMMARY: ========== I am unable to pass along a simple Cookie obtained from a HttpWebRequest call (Machine A's ASP.NET app) so that another Web Server (Machine B) recongnizes the cookie. I...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
7
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because...
1
by: CR1 | last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to...
17
by: Bruno | last post by:
I have a feature that is hosted on a different domain from the primary one in a frame, and need to retain values in a cookie. example: A web page at one.com contains a frame which has a page...
6
by: kelvlam | last post by:
Hello all, I'm still a bit new with JavaScript, and I hope the guru here can shed some light for me. It's regarding handling cookie and the case-sensitive nature of JavaScript itself. My...
1
by: ken | last post by:
How to remove specified cookie (via a given name) in cookie jar? I have the following code, but how can I remove a specified cookie in the cookie jar? cj = cookielib.LWPCookieJar() if cj is...
1
by: jazzdrums | last post by:
Hello, we have migrated our website from .NET 1.1 to .NET 2.0. After this, some of our users are unable to log-on our site, while for the majority of them there's no problem. We're using a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.