VB - ASHX - Read Cookie

Hello All;

It seems that I have just run into a small issue that I am hoping can get resolved pretty quickly, as it is the only thing that is holding me back from completely this part of my task.

In an ASHX file, I am needing to read a cookie to pass its value to a SQL Select statement to pass another value from their to a SQL Insert.

This is what I am using and it breaks everytime.
And since I am using FLASH, it is hard to find out "why" i am getting the error as I cannot view the error code(s).

This is the code

Dim strmegaun As String = context.Request.Cookies("cffmega")("user")

I am passing it to my select statement as:
getUser.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Username", strmegaun))

And it is not working.
I removed the cookie reference and put in the actual value to make sure it got the value and it does, it passes the values to the INSERT statement and everything works fune, until I do the cookie reference. so I know that it is the Cookie
That is causing this issue.

Thank You
LVL 31
Wayne BarronAuthor, Web DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne BarronAuthor, Web DeveloperAuthor Commented:

I tested the code in another site and it works as long as the page is visible.
Since this is running on a JQuery it does not seem to want to work?
Any idea's would be great on this issue.

Craig WagnerSoftware ArchitectCommented:
Have you tried using the debugger to step through the code and make sure you're actually getting the value from the cookie in the first line?

In addition to the above, you could use Fiddler (http://www.fiddler2.com/fiddler2) to watch the traffic between the browser and the web server to ensure the cookie is being sent.

Those are the places you need to start. If hard-coding the value causes it to work it sounds like the cookie either isn't being sent or the code you've written isn't retrieving it correctly.
Wayne BarronAuthor, Web DeveloperAuthor Commented:
I tested it with a AJAX example page, and it worked just fine, the same code did what it was suppose to do, it displayed the value from the cookie.

But not in the JQuery page.
So, I know that the code is correct, just need to find out "why" it does not want to work.

I will check out the link later on this afternoon.
Thanks for the reply.
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Wayne BarronAuthor, Web DeveloperAuthor Commented:
I just tested another JQuery Script, with my cookie implemented in the ashx file
And it worked like it suppose too.
I am going to test out the tool that you have provided here next to see if I can find out what is going on.

Wayne BarronAuthor, Web DeveloperAuthor Commented:
Google Chrome is a A** of a program, it was causing all the problems.
IE8 found the problem when Chrome would not.
I am going to have to test FF to see if it is going to act like Chrome or not.

I logged into the site on Chrome, and was able to navigate, but COULD NOT upload images.
It was not finding me as being logged in.
BUT!!! (This is the A** part)
I went over the IE8 and logged into the site, and wa-la
The dag-on thing worked in both IE and Chrome.

So, my script was right the entire time, and for the last 3 days I was chasing a ghost.
So, what is the deal with Google Chrome?
Does it not read cookies properly when they are sent to it or do you have to be logged into IE or what?

Any incite on the google chrome crap please let me know.

Time to complete the development of my site, I am happy now :)

Wayne BarronAuthor, Web DeveloperAuthor Commented:
To anyone that may be watching this thread, I have hit a break wall that has got me stumped.

VB.NET page.
IE reads the cookie great and without any issues.
(Here are the problems)
Google Chrome will ONLY read the cookie if I have the cookie set in IE, if I logout of IE cookie, then Chrome will not read the cookie in the Upload script.

Cannot someone tell me "why" it would do that for?
This is really confusing and I do not have a clue what needs to be done.
As it works for every page, until I try to upload an image.

It is the uploadify that I am using, and it uses Flash, so it cannot be debugged. (At least I do not know how to debug around the flash part of it, any idea, I am ready to learn)

Wayne BarronAuthor, Web DeveloperAuthor Commented:
To resolve this issue.
Perform the following which makes the cookie reader work across ALL browsers.
Google Chrome, FireFox, IE.

Does not work in Opera, but will try to fix it as well.
But right now, it is working in the 3 primary browsers and that is all that matters.

Code below.
If (context.Request.Cookies("cffmega") Is Nothing) Then
            context.Response.Write("You must be a member and logged in to enter this area!")
            Dim strmegaun As String = context.Request.Cookies("cffmega")("user")
end if

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wayne BarronAuthor, Web DeveloperAuthor Commented:
The test for Opera

Opera will NOT do the multiple uploads, there is some sort of limitation with Opera.
I do not know enough of AJAX to fix that issue.
I will post to the Uploadify forum to see if they can assist.

The script above relating to this topic in post http:Q_25895283.html#31745380
Does work with Opera.
IE, FireFox, Chrome, Opera

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.