Forum Discussion

Rupa_34586's avatar
Rupa_34586
Icon for Nimbostratus rankNimbostratus
Nov 17, 2009

Setting HTTP cookie

My requirment is to set a cookie and then redirect to another uri. Here is the code i am using

 

 

HTTP::cookie insert name "ADPADMIN" value $forcedpod path "/" domain "commonag-portal-dit.nj.adp.com"

 

HTTP::redirect "/public/index.htm"

 

 

i am able to redirect to the uri but not able to set the cookie.

 

Let me know any thoughts

 

4 Replies

  • You can't use HTTP::redirect and set an HTTP header in the redirect response. You can do this using HTTP::respond (Click here):

     

     

    HTTP::respond 302 Location "/public/index.htm" Set-Cookie $my_cookie

     

     

    You can check the wiki page for examples of setting the cookie properties.

     

     

    Aaron
  • I tried using the HTTP::respond.Below is my complete code

     

     

    if ([HTTP::uri] starts_with "/admin/") } {

     

    set forcedpod [string toupper [getfield [HTTP::uri] "/" 4]]

     

    set cookie "ADPADMIN=$forcedpod;path=/;domain=ag-portal.nj.xyz.com"

     

    HTTP::respond 302 "/public/index.htm" "Set-Cookie" $cookie

     

    log local0. "***setting the $forcedpod"

     

    }

     

     

    I am getting page cannot be displayed in the browser.

     

    I could see the "***setting the $forcedpod" in the bigip.means its going into the if block but..somehow its not redirecting.
  • Make sure to include the Location header name in the redirect, as HTTP::respond won't set it automatically like HTTP::redirect does:

     

     

    HTTP::respond 302 Location "/public/index.htm" "Set-Cookie" $cookie

     

     

    Aaron