views:

310

answers:

2

Hi,

The situation: I have 2 webpages with 2 domains (backoffice.myurl.com & www.myurl.com). The backoffice is written in classic asp, the frontend in asp.net 3.5 (vb.net)

When I hit a button in the backoffice, I want to set a cookie on the frontend. I do this by calling a page on the frontend via Microsoft.XMLHTTP

Dim GetConnection
Set GetConnection = CreateObject("Microsoft.XMLHTTP") 
GetConnection.Open "POST", webserviceLocation, False 
GetConnection.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
GetConnection.Send("data=" &value)

In the aspx code I read the posted value and put it in a cookie:

If Not Request.Cookies("mytest3") Is Nothing Then

        Response.Cookies("mytest3").Expires = Now.AddYears(-23)
    End If

    Response.Cookies.Set(New HttpCookie("mytest3", Request.Form.Item("data")))
    Response.Cookies("mytest3").Expires = DateTime.Now.AddYears(30)

On another page on the frontend I want to read that cookie:

Request.Cookies("mytest3").Value

but the Request.Cookies("mytest3") is 'nothing' there. Apparently the cookie is not set. What am I doing wrong or how can I solve this? The pages are called (my debugger hits the breakpoints)

Is this even possible at all?

+2  A: 

When creating the cookie you need to explicitly set the domain:

' I do not remember if the value should be set to myurl.com or .myurl.com
' Please test
Response.Cookies("mytest3").Domain = "myurl.com"

This way the browser will send the cookie along each request to *.myurl.com

Darin Dimitrov
Thanks for your answer, this will probably work but it didn't work in combination with my asp call to the aspx.I used a totally different approach (I skipped the cookie part) and it works perfectly now. Thnx for thinking
Alexander
A: 

Darin has answered your question but you have another problem with this line:-

Response.Cookies("mytest3").Expires = Now.AddYears(-23) 

The response Cookie collection is a differentc collection to that of the Request collection. The response cookies is always empty until code specifically adds a cookie to it. Hence the above line will fail.

AnthonyWJones