?
Solved

Interaction between Applet, Cookie e ASP.net doesn't works in Firefox

Posted on 2010-09-07
6
Medium Priority
?
674 Views
Last Modified: 2012-05-10
Hi!

I have an Applet that gets the username through a cookie set by asp.net page (the page that contains the applet).

Java Code to get the cookie
------------------------------

    private void getUserNameFromCookie() {
        try {
            // get the cookies that are applicable for this applet's parent web page
            URL docBaseUrl = this.getDocumentBase();

            CookieHandler cookieHandler = CookieHandler.getDefault();
            java.util.Map<String, List<String>> headers =
                    cookieHandler.get(docBaseUrl.toURI(),
                    new HashMap<String, List<String>>());

            if (headers.isEmpty()) {
                System.out.println("No cookies found!");
            } else {
                getUserNameFromHeader(headers);
            }
        } catch (Exception e) {
            System.out.println("Unable to get cookie using CookieHandler");
            e.printStackTrace();
        }
    }

    private void getUserNameFromHeader(java.util.Map<String, List<String>> headers) {

        for (String key : headers.keySet()) {
            for (String value : headers.get(key)) {
                if (key.equals("Cookie") && value.startsWith("userName")) {
                    userName = value.split("=")[1];
                }
            }
        }
    }

Open in new window


ASP.net C# code to create the cookie (on Page_Load)
----------------------

            HttpCookie appCookie = new HttpCookie("userName");
            appCookie.Value = Session["user"].ToString();

            appCookie.Expires = DateTime.Now.AddDays(1);
            appCookie.HttpOnly = false;
            Response.Cookies.Add(appCookie);

Open in new window


In IE everything works nice, but in Firefox the operations that requires the username from cookie are not launched.

Any idea on how to resolve this?

Thanks in advance!
0
Comment
Question by:calypsoworld
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 14

Expert Comment

by:Daniel Junges
ID: 33624876
0
 
LVL 14

Expert Comment

by:Daniel Junges
ID: 33624908
0
 

Author Comment

by:calypsoworld
ID: 33631850
Thank you for reply.

Yes, cookies are enabled.
It's weird this works in IE and don't in Firefox....

Java console shows this information after applet's loading (and a lot of other things)

network: Connecting http://localhost:55000/page.aspx with cookie "__utma_a2a=6852338610.1305743161.1274186235.1274560427.1274878003.51; userName=testuser@mail.com"

Apparently there are two cookies in this page (I don't know where the first cookie come from).
Considering that are two cookies in page, am I getting it in the right way in Java?

Thank you.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:calypsoworld
ID: 33632030
I think that is the problem:

Information from Java console...

In IE
network: Connecting http://localhost:55000/page.aspx with cookie "userName=testuser@mail.com"

In Firefox
network: Connecting http://localhost:55000/page.aspx with cookie "__utma_a2a=6852338610.1305743161.1274186235.1274560427.1274878003.51; userName=testuser@mail.com"

Maybe I'm getting the wrong index in Java...
How should script the Java code to get the value in userName field, both in IE and Firefox?
Thanks in advance!
0
 

Accepted Solution

by:
calypsoworld earned 0 total points
ID: 33632651
Problem has been solved.

Thank you junges for your attention!

The problem is actually the what I said in previous post: Firefox contains an 'extra' cookie.
So, the method in Java to get the userName value, both to Firefox (2 cookies) or IE (1 cookie) is the same from the question, but with a simple adjustment.

    private void getUserNameFromHeader(java.util.Map<String, List<String>> headers) {

        for (String key : headers.keySet()) {
            for (String value : headers.get(key)) {
                if (key.equals("Cookie") ) {
                            userName = value.substring(value.indexOf("userName")+9);
                }
            }
        }
0
 
LVL 14

Expert Comment

by:Daniel Junges
ID: 33635103
very good.

regards junges
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question