Solved

Cookie Reading Problem in a PopUp Window

Posted on 2009-05-12
11
190 Views
Last Modified: 2012-06-27
HI Folks,

I am setting a login Cookie which stores fine. But I am trying to read the same cookie in a PopUp window within the same browser session.

I am unable to do that. Any Ideas on how to pass the cookie value to a popup window within the same browser session.

Thanks

RG
Main Browser Window
	Response.Cookies ("Cusername") = Request.Form("login")
		
	Response.Cookies ("Cusername").Expires = dateadd("H",1,now) 
        Response.Redirect("default.asp") ' Go to the main page 
 
From the PopUp Window
 
vUserName = Request.Cookies("Cusername") ' Returns Blank

Open in new window

0
Comment
Question by:rgarimella
  • 7
  • 4
11 Comments
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365180
try this (This is what I use)

<%
' name of the cookie in example is called: Carrzkiss
strUserName = Request.Cookies("Carrzkiss")("Cusername")
If Request.Cookies("Carrzkiss")("Cusername") = "" Then
      Response.Redirect"login/index.asp?Message=You_are_Not_Logged_In"
End If
%>

Carrzkiss

0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365198
Is the name of your cookie    cusername?
Then that would change this to:
User = Being the name of the user logged in.

<%
' name of the cookie in example is called: Carrzkiss
strUserName = Request.Cookies("Carrzkiss")("User")
If Request.Cookies("Carrzkiss")("User") = "" Then
      Response.Redirect"login/index.asp?Message=You_are_Not_Logged_In"
End If
%>

Carrzkiss
0
 

Author Comment

by:rgarimella
ID: 24365319
Hi,

I dont have problems logging in. The problem is reading the value of  Cookie "Cusername" from a popup window, within the same browser session.

The Cookie is setting fine, but unable to read from popup window
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365442
do this
<%
strUserName = Request.Cookies("Carrzkiss")("User")
%>

<%-strUserName%>
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365460
make sure that you are also reading the file that "READS" the cookie.
Make sure that it is an <!--#include file="cookie-reader.asp"-->
If you are not reading the file within' the popup then it would explain as to why it is not reading it.

Popup Window or no Popup window.
It will still read the cookie as long as all refrences are made properly

Good Luck
Carrzkiss
0
 

Author Comment

by:rgarimella
ID: 24365501
Yes,

I did this strUserName = Request.Cookies("Carrzkiss")("User")

But still returns blank

But if I call the page directly inside a browser window instead of a Popup it shows the correct value

0
 

Author Comment

by:rgarimella
ID: 24365527
Could you explain a little bit  about

Make sure that it is an <!--#include file="cookie-reader.asp"-->

Right now I am directly reading the cookie value from a popup
0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24365712
can you make me up a demo of what you are doing?
This way I can have a look at it to see where the issue is?
0
 

Author Comment

by:rgarimella
ID: 24365772
I have 3 files,

login_db.asp (cookie is set fine)

Response.Cookies("ckLogin")("Cusername") = Request.Form("login")

2nd
I have a html file which has a button for window.open

which opens the 3rd file add.asp which has to read the cookie

if I directly open add.asp the cookie is read fine, but when I open from the HTML file in a poup window the cookie is not read

vUserName = Request.Cookies ("ckLogin")("Cusername") ' Returns Blank
0
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 500 total points
ID: 24370712
I just ran a test with a Popup Window using the code that I supplied for you above and it worked without any issue.

This is the code from my Demo Cookie Membership Login Demo that I have up here on EE

(This works without an issue)

Carrzkiss
IsLoggedIn.asp
=======================
<%
strUserName = Request.Cookies("carrzkissCookieDemo")("User")
If strUserName = "" Then
	Response.Redirect"login.asp?Message=You_are_Not_Logged_In"
End If
%>
 
============
in the popup window
<!--#inlcude file="IsLoggedIn.asp"-->
 
Display
<%=strUserName%>

Open in new window

0
 
LVL 30

Expert Comment

by:Wayne Barron
ID: 24379896
did all work out?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
INNER JOIN ? 8 50
Classic ASP application Will support SQL 2014 5 95
Connecting to multiple databases to create a Dashboard 5 49
Set time on Session (ASP) 14 23
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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