cancel
Showing results for 
Search instead for 
Did you mean: 

Reappearing cookies part two:

matt
Active Contributor
0 Kudos

Following on from here, I've now got a simpler example:

But I'm having trouble posting it...

Edited by: Matt on Feb 2, 2009 12:43 PM

Accepted Solutions (1)

Accepted Solutions (1)

matt
Active Contributor
0 Kudos

Page2 has just a button that triggers this code:

* event handler for checking and processing user input and
* for defining navigation
DATA: event TYPE REF TO cl_htmlb_event.
DATA: button_event TYPE REF TO cl_htmlb_event_button.

IF event_id = cl_htmlb_manager=>event_id.
  event = cl_htmlb_manager=>get_event( runtime->server->request ).
  IF event->name = 'button' AND event->event_type = 'click'.
    button_event ?= event.
  ENDIF.

  CASE event->id.
    WHEN 'htmlb_button_1'.

      CALL METHOD _m_response->set_cookie
        EXPORTING
          name   = 'Page2'
          path   = '/'
          value  = 'SET'
          domain = '.mycompany.com'
          secure = 0.

* Put the url of page1 into the next line
      CALL METHOD _m_response->redirect( page1 - defined later).
      CALL METHOD navigation->response_complete.

  ENDCASE.

ENDIF.

Edited by: Matt on Feb 2, 2009 12:46 PM

matt
Active Contributor
0 Kudos

Page 2 layout I can't post for some reason. But it's just a button.

Page 1 layout similarly.

Page 1 has an onInitialization event

* event handler for data retrieval
CONSTANTS: c_username TYPE string VALUE 'Username='.

DATA: page2_url TYPE string,
      value TYPE string.

* Enter URL of page 2 below
page2_url = url of page 2.

* get the value of the entcred cookie
CLEAR value.

DATA: lt_cookies TYPE tihttpcki.
request->get_cookies( CHANGING cookies = lt_cookies ).

CALL METHOD request->get_cookie
  EXPORTING
    name  = 'Page2'
  IMPORTING
    value = value.

IF value IS INITIAL.
* cookie not set -> redirect to page2
  CALL METHOD response->redirect( page2_url ).
  CALL METHOD navigation->response_complete.

ELSE.
* cookie Page2 is set.
  request->delete_cookie( 'Page2' ).
  EXIT.
ENDIF.

Now, I expect page1 to immediately redirect to page 2. Which it does. Then when I press page 2, it should go to page 1, and page 1 shouldn't redirect, but be displayed this time. Which it is. But when I click on refresh in page 1, I expect the cookied "page2" to be deleted. The code runs... but when the initalisation runs again, the cookie is back, and page1 is displayed - the redirection doesn't happen.

matt

Edited by: Matt on Feb 2, 2009 12:49 PM

GrahamRobbo
Active Contributor
0 Kudos

Hi Matt,

I made a couple of changes to your code and it seems to work - I think.

I changed the call where you set the cookie to look like this...

      CALL METHOD _m_response->set_cookie
        EXPORTING
          name   = 'Page2'
          value  = 'SET' .

This is because the path and domain field would need to be specified when interacting with the cookie later on if they are specified here. By defaulting these values I let the HTTP runtime look after this for me.

Then I changed the call to delete the cookie to this...

  response->delete_cookie_at_client( 'Page2' ).

This call will set the expiry timestamp on the cookie to Tue, 01-Jan-1980 00:00:01 GMT so that the browser will discard it.

Cheers

Graham Robbo

matt
Active Contributor
0 Kudos

The complex bit for us is that "page2" is emulating an asp application that we've no control over! ( The application does a re-authentification of the NT password) . So we can't change the way that it creates the cookie.

But, I guess if we can find out what path and domain it sets the cookie on, then we'll be a step forward... At least now I understand what "path" and "domain" are!

I've also considered a solution that doesn't rely on the "page2" cookie at all. I'll play with that and see if it can work that way. We tried it before, but perhaps it also had path and domain problems, because I hadn't considered those at all.

Thanks

matt

matt
Active Contributor
0 Kudos

Thanks to your help, I programmed a work around involving cookies only on "page1".

cheers

matt

Answers (0)