• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Cookie files are being named differently

This is a question that pertains both to javascript and ASP.NET.   I have a .NET web page that creates and reads cookies.  The page also uses a liberal sprinkling of javascript, which also needs to create and read cookies.  The problem I'm experiencing is that the cookies being made on the .NET side are being named differently than the ones on the javascript side.  That is to say, when I look in the cookies folder I see two files.  One is named myusername@localhost[1].txt and the other is names myusername@Myapplicationname[2].txt.  I'm a bit confused as to why this is happening and what I can do so that I only have one cookie for the application.  The .NET code needs to be able to read the cookie value for cookies created in the javascript and visa versa.  

When the cookies are being created, I am NOT indicating a domain name or a path.
The application is NOT https:/
0
tsb5270
Asked:
tsb5270
  • 3
1 Solution
 
raterusCommented:
This is probably something you can figure out rather quickly by examining the HTTP headers, and looking what is happening with the cookies.  I'm guessing you are using IE, so try this program to do it.

http://www.blunck.info/iehttpheaders.html
0
 
raterusCommented:
also, if this is an application that is publically available and you can give a URL, I could see what was up in a matter of minutes if I could access it.
0
 
tsb5270Author Commented:
The solution seemed relatively easy.  I need to add the path attribute.

On the .NET side I created the cookie this way:

 Shared Sub SetCookie(ByRef _httpContext As HttpContext, ByVal CookieName As String, ByVal CookieValue As String, ByVal Expires As Integer)
        Dim appCookie As HttpCookie = New HttpCookie(CookieName)
        appCookie.Value = CookieValue
        appCookie.Path = "/"
        appCookie.Expires = DateTime.Now.AddMinutes(Expires)
    End Sub

In javscript:

function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" + value  +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
0
 
raterusCommented:
This question should be PAQ'd, not deleted, the author solved his/her problem.
0
 
CetusMODCommented:
PAQed with points refunded (250)

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now