7 Replies Latest reply on Dec 19, 2007 8:17 AM by jasonstout13

    How do I access cookies in Flex 2?

      I'm working on a Flex application that will be part of a bigger Asp.net application. This application will require user authentication from within an Asp.net Web Form. Upon a successful authentication I intend to store the session ID in a cookie, so the other applications may use that session ID for authenticating themselves with the server. I will need my Flex application to be able to pull down this same cookie. Is there a way to pull down the cookie from within Flex? If so how do I pull down the cookie? If not then I must say that is a major oversight. I know that Flex can use LSO's but Asp.net cannot. I suppose I could call a javascript function to get the cookie information if Flex does not have cookie support, but that seems kind of hackish. Any help on this would be appreciated.
        • 1. Re: How do I access cookies in Flex 2?
          Flex can't pull down the cookie, but the browser hosting the flex app can, does that make sense?

          here's what I do (same environment, ASP.NET)
          1. Log person in via standard .aspx page. I'm using FormsAuthentication.
          2. After a successful login, their browser has the cookie with whatever you want to stuff in it.
          3. Redirect to page with Flex app.
          4. When flex app makes web service calls or whatever, the browser hosting the flex app is authenticated, because the browser already has the cookie.

          I actually do a little web service call in the background once the user is logged in to grab additional information about the user. The great thing is, the user is already authenticated, so I don't have to have them log in again.

          Hope that helps.

          • 2. Re: How do I access cookies in Flex 2?
            Virus_Hunter Level 1
            So what you're saying is that once a cookie has been created all of my remoting calls will include that cookie? If that's the case that's great. I could just make remoting calls and have each remoting call pull the Session information out of the cookie.
            • 3. How do I access cookies in Flex 2?
              mae@ccg Level 1
              I'm not sure about remoting calls, but I decorate all of my Web Service methods with: <EnableSession(true)>

              Then they can share the same session variables as the session created by the ASP.NET/aspx page.

              Are you using WebOrb or something like that? I'd be surprised if it DID NOT have cookie support baked in.

              Get it? Cookie. Baked. Sorry. Hope that helped.
              • 4. Re: How do I access cookies in Flex 2?
                Virus_Hunter Level 1
                Yeah I'm afraid I do get it. Currently I'm using Fluorine as my Remoting Gateway. I suspect it has the cookies baked in as well. I'm currently working on something that will prove that out. Once I complete the the proof of concept I'll test it out and post my results on the board.
                • 5. Re: How do I access cookies in Flex 2?
                  Will wait for your result hunter. Thanks.
                  • 6. Re: How do I access cookies in Flex 2?
                    Virus_Hunter Level 1
                    I have completed my proof of concept, and I'm very pleased to report that each remoting request does send the Cookie down with it. I am using Flash Remoting with Fluorine as my Gateway, but I suspect that the same remains true for all of the major Gateways. What this means is even though my Flex application my not be able to access cookies directly my server side remoting methods may access all of the cookie information. Furthermore I can provide access to all of the cookie data to my Flex application through Remoting calls to the server. I appreciate all of the help I have received on this issue. You guys have been instrumental in removing a tremendous road block for me.
                    • 7. Re: How do I access cookies in Flex 2?
                      jasonstout13 Level 1
                      I am working on a file uploader for our site, that will let users upload images of robots that they are wanting to sell. I wanted to let them upload more than one image, then when they submit the form we get a list of the images they uploaded. We also check to make sure there is not an image with the same name. If so we append -1, -2 etc... So to let the flex app know what the true url to the renamed image is I set session cookies with php. Everything worked great in IE. I tried it in firefox and nothing... after searching adobe, and google I came across this post. Here is my fix. When the program loads I check for a few cookies, they are used if the user has submited a contact form before, if so it used the cookies to fill in the required fields in the form. Well in the php I added this to the array of cookies...

                      PHP CODE
                      $cookieArray = array("value1"=&gt;$cookie1,"sid"=&gt;session_id());

                      I then have an invisable text line in the flex app named sid, so in flex I put this in the code,

                      AS3 Code
                      sid.text = cookieArray[0]['sid'];

                      then when I call on the upload script I used this.

                      AS3 Code
                      var endpoint:String = "pathToUploadScript.php?sid=" + sid.text;

                      Then on the upload script page i added this to the top, just under the session_start();

                      PHP CODE

                      Now my uploader works great in Firefox, and IE.
                      I have found other solutions to this but this was far much easier and faster. Hope this can help someone that is using flex, php.